When working on this tutorial on Uploading File to OneDrive
from Microsoft Graph OneDrive team, I\'m getting the following error at the last line of the code shown
.ItemWithPath(file.Path)
isn't the path to the file you're uploading, it is the destination path.
For example, if you wanted to upload "SomeFile.txt" to the root of your OneDrive, you would use:
graphClient.Me.Drive // The drive
.Root // The drive's root folder
.ItemWithPath("SomeFile.txt") // The destination to write the upload to
The reason this is currently failing is OneDrive doesn't know what to do with a Windows drive path (i.e. C:\Files\Documents\SomeFile.txt
). It expects a URL safe drive path (i.e. /Documents/SomeFile.txt
).