4

I am in the process of writing a Xamarin.Forms line-of-business application. The app will be targeting UWP and Android.

I have a requirement of being able to store information and pictures taken, in a shared folder on the local storage. This way, multiple users of the same device at different times can resume work-in-progress of the first user.

I am not sure what my options are, as I am unable to write outside of AppData folder (for UWP).

I read about potentially using a Picker and storing the selected folder in the FutureAccessList for UWP, but I am unsure if it will actually work and seems hacky as I will need to come up with a way of doing the same for Android at a later time.

Any ideas/pointers are greatly appreciated!

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
Eric
  • 139
  • 2
  • 11
  • This has nothing to do with a cross-application communication. My situation is: multiple users of the same device at different times will need access to the local data that could have been captured by other user. As in: user A starts the report, takes pictures of an item, goes home. User B during second shift takes the same device and picks up where user A left off. – Eric Feb 06 '18 at 00:53
  • then try https://stackoverflow.com/questions/31184186/sharing-data-files-between-users-in-a-universal-windows-platform-application – Jason Feb 06 '18 at 00:55
  • I have tried the first option via Group Policy before, and that alone didn't work for me. Wasn't aware of the second option... Will give it a shot now and will report back. – Eric Feb 06 '18 at 00:59
  • Ok, I just checked, and setting the value via GP actually set the registry key, which was option #2. :( – Eric Feb 06 '18 at 01:24

1 Answers1

2

There is a special ApplicationData.SharedLocalFolder folder that allows you to share app data across user accounts on a PC. Its main limitation is that it requires appropriate Group Policy:

SharedLocalFolder is only available if the device has the appropriate group policy. If the group policy is not enabled, the device administrator must enable it. From Local Group Policy Editor, navigate to Computer Configuration\Administrative Templates\Windows Components\App Package Deployment, then change the setting "Allow a Windows app to share application data between users" to "Enabled."

I feel that the fact that this is not allowed by default is a great obstacle to the usefulness of this API.

There a publisher cache folder, but this solution is not appropriate for you because of documentation says:

Publisher Cache shares data across apps for the current user

So I would probably really go with the picker-based solution you proposed. Offer the user to select a folder to save the data to using the FolderPicker and then store the selected folder to the FutureAccessList. The future access list is reliable and can even track the changes of the selected item (like when the user moves it to a different location). The abstraction of the selection process in a cross-platform manner may be a bit more complicated, but it should be possible to hide it behind a dependency service implementation. My guess will provide an async method that will initialize the target location. On UWP this will check the FutureAccessList if a location was selected previously and if it was not, it will use the FolderPicker to let the user select it and will store it for future user afterward. On Android, it will work in Android specific manner (I am not sure what are the options there). Then the service will have some file manipulation methods that will abstract the platform-specific manipulation with the folder (I think you cannot use the common System.IO namespace, as you cannot directly access the user selected folder outside of the StorageFolder API)

Martin Zikmund
  • 38,440
  • 7
  • 70
  • 91
  • Hi Martin, thank you for taking the time to look into this. This would be platform-specific implementation, that will make it difficult if not impossible to leverage the shared cross-platform code, especially the plug-ins. I was hoping that there was/is a platform-agnostic abstraction in Xamarin.Forms that would provide the necessary functionality. – Eric Feb 06 '18 at 11:05
  • You can still use the content of the files in cross platform manner, is there a specific functionality you are missing? – Martin Zikmund Feb 06 '18 at 11:17
  • You can also get a `System.IO.Stream` from a `StorageFile` using the `OpenStreamForReadAsync` method – Martin Zikmund Feb 06 '18 at 11:19
  • The users will take pictures of items being appraised. I was planning on using the [MediaPlugin](https://github.com/jamesmontemagno/MediaPlugin) for taking pictures. I believe it takes directory, relative to the application installation path, or allows saving in the camera roll (album). In order for me to persist the images in the shared folder, I might have to first store in the album, get the stream, and then save it in the shared folder, then remove from album. That seems really "hacky", and I was trying to avoid that. :( – Eric Feb 06 '18 at 12:35