1. ochhanz's Avatar
    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/mag...or=-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.
    05-20-2019 09:47 AM
  2. Ryujingt3's Avatar
    05-21-2019 09:40 AM
  3. ochhanz's Avatar
    I am no developer, but can this help you?

    https://github.com/OneDrive/onedrive-sdk-csharp
    , thanks for replying I appreciate you taking the time, I indeed already have seen that page. I did found some more guides when duckduckgoing so hopefully one of those guides will contain a solution to my problem.
    05-22-2019 09:35 AM
  4. Ryujingt3's Avatar
    05-24-2019 08:22 AM
  5. ochhanz's Avatar
    , thanks, I will check it out.

    Also found 30DaysMSGraph (haven't read/watched it entirely yet), might be interesting to others facing the same issues.
    05-31-2019 05:52 AM
  6. Ryujingt3's Avatar
    , thanks, I will check it out.

    Also found 30DaysMSGraph (haven't read/watched it entirely yet), might be interesting to others facing the same issues.
    Good luck with the coding. What kind of app are you making?
    05-31-2019 09:16 AM
  7. ochhanz's Avatar
    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 :\.
    06-01-2019 06:02 AM
  8. Ryujingt3's Avatar
    Did any of the links help you out so far? Did you check the path in your code?
    06-01-2019 08:36 AM
  9. ochhanz's Avatar
    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.
    06-02-2019 12:00 PM
  10. Ryujingt3's Avatar
    Did you try posting your code on somewhere like StackExchange to get advice?
    06-03-2019 08:52 AM
  11. ochhanz's Avatar
    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.'
    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.
    06-03-2019 09:48 AM
  12. Ryujingt3's Avatar
    , 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.'
    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!
    ochhanz likes this.
    06-04-2019 08:10 AM

Similar Threads

  1. Replies: 0
    Last Post: 05-18-2019, 06:18 PM
  2. OneDrive on Android
    By jasqid in forum OneDrive
    Replies: 0
    Last Post: 05-14-2019, 03:04 PM
  3. OneDrive Backups of Backups ?
    By ReprobusR in forum OneDrive
    Replies: 1
    Last Post: 05-12-2019, 01:04 PM
  4. OneDrive Space on Phone
    By ReprobusR in forum OneDrive
    Replies: 0
    Last Post: 05-12-2019, 11:37 AM
  5. Silent programmatic configuration of OneDrive
    By John Muckley in forum OneDrive
    Replies: 0
    Last Post: 04-10-2019, 10:24 AM
LINK TO POST COPIED TO CLIPBOARD