I'm trying to update a drive item's parent reference, where the drive item's name or the new parent path containing special characters (%25
for example), and both new parent and item are in the same Group and Drive.
When the new parent's path contains those characters I get an invalid request exception.
When the update drive item's name contains those character I get an "Item Not Found" exception, but the item is moved to the destination after the 25
was stripped from the item's name.
My code works fine except for these two scenarios.
Here is what i try to do:
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);
OneDrive doesn't support %
(or several other special characters) in file or path names. This isn't related to Microsoft Graph, they aren't supported by OneDrive itself (or many file systems for that matter).
From Invalid file names and file types in OneDrive, OneDrive for Business, and SharePoint:
Characters that aren't allowed in file and folder names in OneDrive, OneDrive for Business on Office 365, and SharePoint Online:
" * : < > ? / \ |
Characters that aren't allowed in file and folder names in OneDrive for Business on SharePoint Server 2013:
~ " # % & * : < > ? / \ { | }.