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 below:
Remarks: There are some posts online with a related issue, (such as: This, or this, or this or this or this). But they all seem to have a different context or do not have a response.
Question: What could be the issue, and how can we resolve it
Resource not found for the segment 'root:'
Relevant Code:
GraphServiceClient graphClient = ProviderManager.Instance.GlobalProvider.Graph;
var picker = new Windows.Storage.Pickers.FileOpenPicker();
....
picker.FileTypeFilter.Add("*");
Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();
if (file != null)
{
// Application now has read/write access to the picked file
// request 1 - upload small file to user's onedrive
Stream fileStream = await file.OpenStreamForReadAsync();
DriveItem uploadedFile = await graphClient.Me.Drive.Root
.ItemWithPath(file.Path)
.Content
.Request()
.PutAsync<DriveItem>(fileStream);
}
OneDrive
is mapped to myWindows - 10
's file explorer pathC:\MyFolder
. And thenOneDrive
folder structure has built-in foldersAttachments, Documents, Pictures
. Hence, usinggraphClient.Me.Drive.Root.ItemWithPath("/Documents/SomeFile.txt")
would upload the file toOneDrive
's built-in folderDocuments
, correct? – Palaeogene