首页 > 解决方案 > 使用特殊字符更新 DriveItem 会返回错误

问题描述

我正在尝试更新驱动器项的父引用,其中驱动器项的名称或包含特殊字符(%25例如)的新父路径,并且新父项和项都在同一个组和驱动器中。

除了这两种情况外,我的代码工作正常。

这是我尝试做的事情:

destinationPath = Uri.EscapeDataString(destinationPath);

var destination = await client
    .Groups[groupId]
    .Drives[driveId]
    .Root
    .ItemWithPath(destinationPath)
    .Request()
    .GetAsync();

DriveItem newItem = new DriveItem {
    ParentReference = new ItemReference { Id = destination.Id }
};

sourcePath = Uri.EscapeDataString(sourcePath);

var movedItem = await client
    .Groups[groupId]
    .Drives[driveId]
    .Root
    .ItemWithPath(sourcePath)
    .Request()
    .GetAsync();

var result = await client
    .Groups[groupId]
    .Drives[driveId]
    .Items[movedItem.Id]
    .Request()
    .UpdateAsync(newItem);

标签: c#microsoft-graph-apionedrive

解决方案


OneDrive 不支持%文件名或路径名(或其他几个特殊字符)。这与 Microsoft Graph 无关,OneDrive 本身(或许多文件系统)不支持它们。

OneDrive、OneDrive for Business 和 SharePoint 中的无效文件名和文件类型

OneDrive、OneDrive for Business on Office 365 和 SharePoint Online 中的文件和文件夹名称中不允许使用的字符:" * : < > ? / \ |

SharePoint Server 2013 上 OneDrive for Business 的文件和文件夹名称中不允许使用的字符:~ " # % & * : < > ? / \ { | }.


推荐阅读