问题
I noticed that file saved into ApplicationData.Current.LocalFolder.CreateFileAsync folder is removed after application uninstall.
Is that possible to save file that will remain in user profiler after application uninstall , so when user re-install application I can read settings from file for this user ?
回答1:
Only these two ways are possible:
Ask your user to pick a file or a folder using
FilePicker
orFolderPicker
and then track them in yourMostRecentlyUsedList
. Then you'll get the permission to access user's permanent file or folder. But you should notice that you must ask your user again to select the same file or folder after uninstalling/installing your app. See the Microsoft docs below to know more about them.- Open files and folders with a picker - UWP app developer | Microsoft Docs
- Track recently used files and folders - UWP app developer | Microsoft Docs
Try to use your cloud server to store the permanent files. This is the method that most network company products do. If you have to power and money to build or rented server, I recommend you to try this way. But it is a waste of time and money to do this in a small personal app.
For conclusion, There is no way to store a permanent file easily like Win32 Desktop Application.
回答2:
Not without the user's consent. You will have to implement a save / load functionality to ask the user where to save the file (like Document) and then to select the file to restore.
回答3:
If your file is a small one, you can store it in ApplicationData.Current.RoamingFolder
, which gets roamed across the user's devices. Disadvantages of this approach are that the file can get overwritten quite easily because of late sync from one of the devices and the fact that the file stays on cloud only for a limited time after the user uninstalls the app from all his devices. See more details about roaming here in Docs.
Apart from this, your only solution would be to either store the file on the users drive with his consent (using FileSavePicker
or FolderPicker
) or on his OneDrive, which is quite common as a backup option (here you need to integrate the OneDrive SDK and get user's consent).
来源:https://stackoverflow.com/questions/46382423/c-sharp-uwp-store-app-how-to-save-file-that-will-not-be-deleted-after-app-uninst