Delete files when uninstall the application

Stefano M 91 Reputation points
2021-03-26T19:02:52.333+00:00

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

Developer technologies | .NET | Xamarin
{count} votes

1 answer

Sort by: Most helpful
  1. Cole Xia (Shanghai Wicresoft Co,.Ltd.) 6,756 Reputation points
    2021-03-29T09:38:40.973+00:00

    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://learn.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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.