Search code examples
c#uwponedrive

Sharing a file in OneDrive between different users of the same app


My UWP app needs to share some xml files between different users. Let's say user A creates the files, and user B needs to access them (read and write).

The files are saved by user A to the App folder on her OneDrive (OneDrive > Apps > MyApp > file.xml).

Now when user B is using the app, he needs to access the files on A's OneDrive.

As far as I can tell, using the C# OneDrive SDK I have two ways to have B access the files:

1) User A shares the MyApp folder with user B, and sends him the folder id. User B enters the folder id in the app and the app can get to the files using the folder id.

2) User A shared the MyApp folder with user B; user B adds the shared folder to his OneDrive; now the app can search for the folder by looking through the children of Drive/Root and finding a folder that has the right name and has a remote item. The app can get to the files using the remote item id.

I don't really like either solution because both of them rely on work by the user that is error prone and likely not something that they have had to do before (sending a weird id in an email, entering it in the app, or adding the shared folder to one's OneDrive).

Ideally I would have user A share the folder with B and then the app would somehow find it through B's OneDrive (without B explicitly adding it) but I haven't found a way to do that with the C# SDK.


Solution

  • For whoever has the same problem:

    As it turns out, it should be possible to find folders shared with the user through the API, but it doesn't work because of this bug: https://github.com/OneDrive/onedrive-sdk-csharp/issues/133

    There is a fix for the bug that applies only to version 1.2 of the API amd it can be found in this branch: https://github.com/OneDrive/onedrive-sdk-csharp/tree/v1-maintenance