Onedrive sdk itemNotFound

ochhanz

Member
Nov 15, 2017
512
1
18
Visit site
Hi all,

For my UWP app I want add Onedrive function so the user can upload and download a file from his/her Onedrive. So I followed this guide from Microsoft / MSFT (https://msdn.microsoft.com/en-us/magazine/mt632271.aspx?f=255&MSPPError=-2147217396 ).
The uploading part works (I see newly created files in my onedrive account that I can open manually) but the downloading/reading part gives the following error:
"Microsoft.Graph.ServiceException: Code: itemNotFound
Message: Item does not exist"

But the item / file does exist and the path used is the same as when I upload the file. I also checked if I added right scopes, and checked if it worked with User.Read / files.read.all. I also tried the newer version of the Onedrive SDK which is within the Microsoft Graph API, but I got the same error.

Here is my code in c# to read the file (note that the exception is thrown so the try{} part fails):
var _scopes = new[]
{
"onedrive.readwrite",
"onedrive.appfolder",
"wl.signin"
};
var _client = OneDriveClientExtensions.GetUniversalClient(_scopes);
var _session = await _client.AuthenticateAsync();
Debug.WriteLine($"Token: {_session.AccessToken}");

var builder = _client.Drive.Root.ItemWithPath("Public/Test"); ///MyFile.txt
try
{
var file = await builder
.Request()
.GetAsync();
var contentStream = await builder.Content
.Request()
.GetAsync();
Debug.WriteLine($"Content for file {file.Name}:");
using (var reader = new StreamReader(contentStream))
{
Debug.WriteLine(reader.ReadToEnd());
}
}
catch (Exception ex)
{
Debug.WriteLine("Onedrive builder request exception: " + ex.ToString());
}

Does anyone perhaps know how to solve this issue or where I can get a book about the Onedrive sdk? I want to learn more about this but MSFT's documentation does not help me much. :unhappy:
 

ochhanz

Member
Nov 15, 2017
512
1
18
Visit site
Good luck with the coding. What kind of app are you making?
, a flexible note app, apart from mostly this import issue it is ready lol.

I did notice that I can read a file from onedrive right after I saved it by using its file Id (which is generated on the fly by onedrive I think), so most likely my path is wrong in the code above. Probably something super obvious that I am still missing :\.
 

ochhanz

Member
Nov 15, 2017
512
1
18
Visit site
Did any of the links help you out so far? Did you check the path in your code?
, well the problem is that one is outdated (the one that uses 2014 uses Windows Live) and for the other one I prefer to avoid using third party API's.
Yeah I debugged the path, it is the same as the upload path which works perfectly so I am still not sure what to think. I will re-read the original article again.
 

ochhanz

Member
Nov 15, 2017
512
1
18
Visit site
Did you try posting your code on somewhere like StackExchange to get advice?
, I feel so stupid now lol, my own path string to the file was correct but the one I was using to reach the app root was wrong. I was using 'client.Drive.Root.' while I should have been using 'client.Drive.Special.AppRoot.' :angel:
I think I overlooked earlier this since the import example in Microsoft's guide uses the .Root while the export example uses .AppRoot, kindy confusing of them but at least I learned some new things while searching for the solution.
 

Ryujingt3

New member
Nov 13, 2013
3,310
1
0
Visit site
, I feel so stupid now lol, my own path string to the file was correct but the one I was using to reach the app root was wrong. I was using 'client.Drive.Root.' while I should have been using 'client.Drive.Special.AppRoot.' :angel:
I think I overlooked earlier this since the import example in Microsoft's guide uses the .Root while the export example uses .AppRoot, kindy confusing of them but at least I learned some new things while searching for the solution.

Does that mean you fixed the issue? If so, that's awesome! Well done!
 

Members online

Forum statistics

Threads
322,736
Messages
2,242,598
Members
427,978
Latest member
Duouser3