question

StefanoM-9408 avatar image
0 Votes"
StefanoM-9408 asked ColeXia-MSFT commented

Delete files when uninstall the application

If I try to uninstall the application I would like the files to be deleted, but if I uninstall the application and reinstall it the contents of the files remain. how could i solve?

 switch (Device.RuntimePlatform)
             {
                 case Device.iOS:
                     dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "DbLocal.db3");
                     break;
                 case Device.Android:
                     dbPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "DbLocal.db3");              
                     break;
             }

I have problems with the files on every page, and until recently everything works perfectly. Even if I create new files, or add strings to existing ones, when I restart the application the changes no longer exist. If I try to connect the physical devices to the PC, and I go to the folder of my application, the files do not exist.

If you try to change the terminal instead, the problem does not exist, but until yesterday it works on both

dotnet-xamarinforms
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

ColeXia-MSFT avatar image
0 Votes"
ColeXia-MSFT answered ColeXia-MSFT commented

Hello,

Welcome to Microsoft Q&A!

Are you test on iOS ?

If we choose MyDocuments , the file may be backed up to iCloud in this folder , this is the reason the file remains if app is reinstalled .

We could change it to Library/YourData and apply the do not back up attribute to prevent the files from using up iCloud Backup .

var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
var filename = Path.Combine (documents, "LocalOnly.txt");
File.WriteAllText(filename, "This file will never get backed-up. It would need to be re-created after a restore or re-install");
NSFileManager.SetSkipBackupAttribute (filename, true); // backup will be skipped for this file


Please note : NSFileManager.SetSkipBackupAttribute (filename, true); must be called in iOS project.


Refer to https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/file-system#complying-with-ios-5-icloud-backup-restrictions .


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I haven't done any tests on iOS yet, the problem occurs to me on Android.

0 Votes 0 ·

Could you provide all the code? I will try to reproduce your problem on my physical device .

0 Votes 0 ·