locked
[UWP][C#] Questions about OneDrive access RRS feed

  • Question

  • So, I have been searching pretty much all day on some issues I'm facing. I'm working on an app which allows users to save a file anywhere on their desktop PC, including OneDrive, using the FileSavePicker. The user can also open any file using the FileOpenPicker.

    This is working great!

    Except, when I began more testing on my Windows Phone, I realized there are some problems. When I tap my button to open the file, I get the OpenFilePicker, and I navigate to the OneDrive location and pick the file. BUT, it actually downloads a copy of the file and saves it to some deep nested local app package storage location somewhere. I can make changes to the file just fine, but to no surprise, it does not get uploaded back to OneDrive.

    I found a topic with generally the same problem:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/4d16bdc8-0e61-46d2-8803-8c8e042b2262/onedrive-and-fileopenpicker?forum=wpdevelop

    I know why it isn't working. So my questions are this:

    1. Is there a reason that I can access OneDrive and can open and save files just fine on the desktop, but on phone I cannot?

    2. Is there any way around this without having to deal with the Live SDK? As I mentioned earlier, the user is able to select files in any location, not just OneDrive. So it seems kind of silly to use the SDK in only one case, and force them to sign in from my app, just to be able to select a file from OneDrive using the FileOpenPicker (which they already have access to anyway).

    3. If I do have to use the Live SDK, how can I allow the user to open files on their USB drive, and also OneDrive using the API, or would I have to have 2 options: "Open from OneDrive" and "Open File From Somewhere Else"?

    Sorry, its just I have little experience with Live SDK, and I don't want to start spending an enormous amount of time trying to figure it out if there is another way.

    Any help would be greatly appreciated.

    Thanks


    Neptune Century

    Saturday, September 19, 2015 7:47 PM

Answers

  • I don't know about that.

    An opened file from OneDrive creates a StorageFolder item, which has methods to write and change the file. It seems kinda... "pointless" to write changes to a temp file I can do nothing with.

    I do see what you are saying tho, that OneDrive is an app. But isn't it integrated with Windows 10? Shouldn't there be some mechanism by which a change made to the file should trigger it to be uploaded back to OneDrive? I can create a file on OneDrive using the FileSavePicker on the phone, but so far the open > change > upload step is eluding me.

    Maybe I'm just kicking a dead horse here.


    Neptune Century

    Probably you already understood but I just want to make it clear. It is integrated differently on desktop on phone. On desktop, you have a dedicated folder to store local copy of files from OneDrive and a background task constantly looking for changes in the folder and sync the changes back. On phone, you don't have that dedicated folder due to storage limitation, files are downloaded directly from OneDrive when requested. And you don't have the constant background task because (1) there is no fixed folder to look for and (2) to save battery.
    • Marked as answer by neptunecentury Thursday, October 8, 2015 5:19 PM
    Thursday, October 8, 2015 3:18 PM

All replies

  • Hello Neptune Century,

    Welcome to the MSDN forum.

    >>I know why it isn't working. So my questions are this:

    Please ask one question for per thread. And for your question 1 and 3, they should be related with Live SDK, I think they are better ask to Live Connect forum, while it seems that now this forum is moved to Stack Overflow, so it is better ask this issue to stackoverflow forum.

    >>2. Is there any way around this without having to deal with the Live SDK?

    As far as I know, in windows runtime development, the only way to access data stored in onedrive is to use the Live SDK.

    Regards.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    • Edited by Fred Bao Tuesday, September 22, 2015 8:32 AM
    • Proposed as answer by Fred Bao Wednesday, September 30, 2015 9:39 AM
    • Unproposed as answer by neptunecentury Wednesday, September 30, 2015 12:32 PM
    Tuesday, September 22, 2015 8:31 AM
  • I asked a similar question on StackOverflow since it is related to live SDK

    http://stackoverflow.com/questions/32717453/c-sharp-uwp-liveskd-and-onedrive-access-using-fileopenpicker/32855017#32855017

    I have searched a lot on this and had found similar issues, all with no resolutions. According to the OneDrive API, the FileOpenPicker and FileSavePicker should allow saving to and opening from OneDrive. And it does. But the problem I'm having with the built-in file pickers, is that on the Phone device, the file opened from the OpenFilePicker is downloaded to a temp location, edited, but never synced back.

    I read this forum topic, which is pretty much the exact same issue:

    https://social.msdn.microsoft.com/Forums/windowsapps/en-US/4d16bdc8-0e61-46d2-8803-8c8e042b2262/onedrive-and-fileopenpicker?forum=wpdevelop#2507e8a5-cc1b-4176-b20c-c562dade0947

    and this one has no answers either.

    In my opinion, this is something that should just work. I'm not interested in LiveSDK development, when all I need is to open a file from OneDrive that the user selects with a built-in FileOpenPicker, edit it, and have it synced back to OneDrive.


    Neptune Century

    Wednesday, September 30, 2015 12:31 PM
  • So a simple workaround is you could save the file from onedrive to local and the use the built-in fileopenpicker to let use select the downloaded file.
    Thursday, October 8, 2015 10:59 AM
  • So a simple workaround is you could save the file from onedrive to local and the use the built-in fileopenpicker to let use select the downloaded file.

    Thanks for your suggestion, however, the problem isn't opening the file, its when changes are written to the file, they don't get synced back to OneDrive because it is in a local storage folder after being opened.

    The following may help clarify:

    1. File is saved to OneDrive from app on user's desktop using FileSavePicker.

    2. User opens app on phone and browses for file using FileOpenPicker.

    3. The file is then downloaded from OneDrive into the app's local storage.

    4. Modifications are made to the file using the StorageFile's built in methods.

    5. File is not synced back to OneDrive, so when user goes back to his/her desktop, the changes are not synced.

    Anyway, this seems like either a bug, or a limitation of the Windows 10 Mobile that isn't clearly stated in the OneDrive SDK. I know Windows 10 Mobile isn't complete yet, so perhaps it is a bug. I don't know. But the SDK clearly states that the files can be opened and saved to OneDrive using the pickers.

    Any insights on this? Thanks!


    Neptune Century

    Thursday, October 8, 2015 12:38 PM
  • So a simple workaround is you could save the file from onedrive to local and the use the built-in fileopenpicker to let use select the downloaded file.

    Thanks for your suggestion, however, the problem isn't opening the file, its when changes are written to the file, they don't get synced back to OneDrive because it is in a local storage folder after being opened.

    The following may help clarify:

    1. File is saved to OneDrive from app on user's desktop using FileSavePicker.

    2. User opens app on phone and browses for file using FileOpenPicker.

    3. The file is then downloaded from OneDrive into the app's local storage.

    4. Modifications are made to the file using the StorageFile's built in methods.

    5. File is not synced back to OneDrive, so when user goes back to his/her desktop, the changes are not synced.

    Anyway, this seems like either a bug, or a limitation of the Windows 10 Mobile that isn't clearly stated in the OneDrive SDK. I know Windows 10 Mobile isn't complete yet, so perhaps it is a bug. I don't know. But the SDK clearly states that the files can be opened and saved to OneDrive using the pickers.

    Any insights on this? Thanks!


    Neptune Century

    I think it is a limitation rather than a bug. On desktop, you have a OneDrive folder a background task to monitor change in the OneDrive folder and sync the change if necessary. On phone, you don't even have the OneDrive folder, it's just an app that connect to OneDrive and download the file if you request it. Big difference. I think this is to save power on Windows Phone.

    Thursday, October 8, 2015 2:03 PM
  • I don't know about that.

    An opened file from OneDrive creates a StorageFolder item, which has methods to write and change the file. It seems kinda... "pointless" to write changes to a temp file I can do nothing with.

    I do see what you are saying tho, that OneDrive is an app. But isn't it integrated with Windows 10? Shouldn't there be some mechanism by which a change made to the file should trigger it to be uploaded back to OneDrive? I can create a file on OneDrive using the FileSavePicker on the phone, but so far the open > change > upload step is eluding me.

    Maybe I'm just kicking a dead horse here.


    Neptune Century

    Thursday, October 8, 2015 2:35 PM
  • I don't know about that.

    An opened file from OneDrive creates a StorageFolder item, which has methods to write and change the file. It seems kinda... "pointless" to write changes to a temp file I can do nothing with.

    I do see what you are saying tho, that OneDrive is an app. But isn't it integrated with Windows 10? Shouldn't there be some mechanism by which a change made to the file should trigger it to be uploaded back to OneDrive? I can create a file on OneDrive using the FileSavePicker on the phone, but so far the open > change > upload step is eluding me.

    Maybe I'm just kicking a dead horse here.


    Neptune Century

    Probably you already understood but I just want to make it clear. It is integrated differently on desktop on phone. On desktop, you have a dedicated folder to store local copy of files from OneDrive and a background task constantly looking for changes in the folder and sync the changes back. On phone, you don't have that dedicated folder due to storage limitation, files are downloaded directly from OneDrive when requested. And you don't have the constant background task because (1) there is no fixed folder to look for and (2) to save battery.
    • Marked as answer by neptunecentury Thursday, October 8, 2015 5:19 PM
    Thursday, October 8, 2015 3:18 PM
  • Ok, so I guess I will just have to accept that this will likely never work. I decided to change the structure of the app and build a web service instead of working with files directly. It opens a can of worms I didn't want to deal with, but it seems I don't have a choice.

    I appreciate your help.


    Neptune Century

    Thursday, October 8, 2015 5:19 PM
  • I discovered this thread attempting to do the same thing Neptune wanted to do; open a file from OneDrive then save the changes back to it.

    I hit the same issue; the file is downloaded locally.  Since the same flow occurs when I do this with Excel, I assume it's something to live with.  However, I can't figure out how to detect that it came from OneDrive.  The StorageFile points to the local file path on the phone and the StorageProvider is computer, not OneDrive.  Is there any method for determining it's original OneDrive location so I can figure out  how to write it there instead of saving the local file?

    Thanks.


    Hornist

    Monday, January 18, 2016 9:56 PM
  • It is integrated differently on desktop on phone. On desktop, you have a dedicated folder to store local copy of files from OneDrive and a background task constantly looking for changes in the folder and sync the changes back. On phone, you don't have that dedicated folder due to storage limitation, files are downloaded directly from OneDrive when requested. And you don't have the constant background task because (1) there is no fixed folder to look for and (2) to save battery.


    illidanx

    This has nothing to do with different implementations, dedicated folders, background tasks on desktop or saving battery.

    UWP/WinRT has specific contract for this task, called CachedFileUpdater, which purpose is exactly what OP is trying to achieve - it detects changes for files it provided through file picker, and starts background task with necessary logic for updating those files. In case of OneDrive app this background task suppose to update cloud copy of the file. Also, background task can be called each time client app access this file to check if newer version exists in the cloud.

    Perfect example of how it should work is official DropBox app. It does exactly what you expect - uploads changed file to DropBox and provides updated file on request. It seems like OneDrive app simply doesn't implement this contract. I'm sure there is some far-fetched reason for this, but fact is a fact.

    Here is a bit more info on CachedFileUpdater contract, and you can also check UWP sample.

    Monday, April 11, 2016 3:33 PM