OS: Win11
Graph API: Version 5
Graph API Permissions: Users.Read, Files.ReadWrite
No errors are thrown. I've turned on the logging for the graph api calls and noticed no errors in there either.
The call works perfectly fine for me, but I'm the owner of the sub folder in the OneDrive.
I even went so far as to update the access to the sub folder so that at least one user had the write to edit items in that folder.
A similar post to this one from several years ago recommended Files.ReadWrite.All.
Can someone confirm this? I don't have the level of access to grant these permissions to everyone in the company, let alone one person. I'd like to approach our security group with certainty and not just another well-intentioned guess.
private async static Task UploadFile(string filePath)
{
string oneDriveRootId = "-- drive id of root OneDrive folder --";
string itemId = "-- ID OF SUBFOLDER --";
try
{
byte[] data = System.IO.File.ReadAllBytes(filePath);
using (Stream stream = new MemoryStream(data))
{
var graphClient = GraphAuthentication.GetGraphServiceClient(loggedOnUserEmail);
var item = await graphClient.Drives[oneDriveRootId]
.Items[itemId]
.ItemWithPath(filePath)
.Content
.PutAsync(stream);
}
}
catch (Exception ex)
{
Console.WriteLine(" Error uploading {0}\n\n{1}", filePath, ex);
}
}
Yes, you'll need Files.ReadWrite.All
to have permission to make calls against a drive that is NOT your own. The Files.ReadWrite
scope only grants the calling application permission to the callers drive.