Search code examples
c#windows-8local-storagestoragefile

How to Delete Files and Application Data Container Values in One Go?


I have a reset function in my app which brings the app back to default state. There for I need to remove the four files I created and remove the settings I created in the ApplicationDataContainer. This is how I remove the files

try
{
    StorageFile file = await localfolder.GetFileAsync("HistoryFile");
    if (file != null)
    {
        await file.DeleteAsync();
    }
}
catch
{
    //Catch Process
}

Is there a function which removes all the files together? When I tried the following code

localfolder.DeleteAsync()

It removed the LocalState folder along with the files, I jus need to remove the files not the folder.

And is there anyway in which I jus can remove all the values stored in ApplicationDatacontainer in one go? rather than removing them one by one like this?

localSettings.DeleteContainer("exampleContainer");

Solution

  • If you want to remove application data from its local data store, try this.

    await Windows.Storage.ApplicationData.Current.ClearAsync(
         Windows.Storage.ApplicationDataLocality.Local);