Export (0) Print
Expand All

Deleting Stores

IsolatedStorageFile supplies two methods for deleting isolated storage files:

  • The instance method Remove does not take any arguments and deletes the store that calls it. No permissions are required for this operation. Any code that can access the store can delete any or all the data inside it.
  • The static method Remove takes the IsolatedStorageScope value User, and deletes all the stores for the user running the code. The IsolatedStorageFilePermission permission for the IsolatedStorageContainment value AdministerIsolatedStorageByUser is required for this operation.

DeletingStores Example

The following code example demonstrates the use of the static and instance Remove methods. The class obtains two stores, one isolated for user and assembly and one isolated for user, domain, and assembly. The user, domain, and assembly store is then deleted by calling the Remove method of the IsolatedStorageFile isoStore1. Then, all remaining stores for the user are deleted by calling the static method IsolatedStorageFile.Remove.

Imports System
Imports System.IO.IsolatedStorage

Public Module modmain

   Sub Main()

      ' Get an isolated store for user, domain, and assembly and put it into 
      ' an IsolatedStorageFile object.

      Dim isoStore1 As IsolatedStorageFile
      isoStore1 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly Or IsolatedStorageScope.Domain, Nothing, Nothing)

      ' Get a store for user and assembly and put it into a different
      ' IsolatedStorageFile object.

      Dim isoStore2 As IsolatedStorageFile
      isoStore2 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or IsolatedStorageScope.Assembly, Nothing, Nothing)

      ' The Remove method deletes a specific store, in this case the
      ' isoStore1 file.

      isoStore1.Remove()
      Console.WriteLine("The user, domain, and assembly store has been removed.")


      ' This static method deletes all the isolated stores for this user.

      IsolatedStorageFile.Remove(IsolatedStorageScope.User)
      Console.WriteLine("All isolated stores for this user have been deleted.")

   End Sub
End Module

[C#]
using System;
using System.IO.IsolatedStorage;

public class DeletingStores{

   public static void Main(){

      // Get a new isolated store for this user, domain, and assembly.
      // Put the store into an IsolatedStorageFile object.

      IsolatedStorageFile isoStore1 =  IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Domain | IsolatedStorageScope.Assembly, null, null);
      Console.WriteLine("A store isolated by user, assembly, and domain has been obtained.");

      // Get a new isolated store for user and assembly.
      // Put that store into a different IsolatedStorageFile object.

      IsolatedStorageFile isoStore2 = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
      Console.WriteLine("A store isolated by user and assembly has been obtained.");

      // The Remove method deletes a specific store, in this case the
      // isoStore1 file.

      isoStore1.Remove();
      Console.WriteLine("The user, domain, and assembly isolated store has been deleted.");
      
      // This static method deletes all the isolated stores for this user.

      IsolatedStorageFile.Remove(IsolatedStorageScope.User);
      Console.WriteLine("All isolated stores for this user have been deleted.");

   }// End of Main.

}

See Also

Performing Isolated Storage Tasks | IsolatedStorageFile

Show:
© 2014 Microsoft