如何:删除独立存储中的存储区

更新:2007 年 11 月

IsolatedStorageFile 提供了两种删除独立存储文件的方法:

  • 实例方法 Remove 不带任何参数,而且可以删除调用它的存储区。该操作不需要任何权限。可以访问存储区的任何代码都可以删除该存储区中的任何数据或所有数据。

  • 静态方法 Remove 采用 IsolatedStorageScopeUser,并删除运行该代码的用户的所有存储区。此操作需要 IsolatedStorageContainmentAdministerIsolatedStorageByUserIsolatedStorageFilePermission 权限。

DeletingStores 示例

下面的代码示例演示如何使用静态和实例 Remove 方法。类获得两个存储区,一个按用户和程序集隔离;另一个按用户、域和程序集隔离。然后,通过调用 IsolatedStorageFileisoStore1 的 Remove 方法,删除用户、域和程序集存储区。接下来,通过调用静态方法 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
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.

}

请参见

参考

IsolatedStorageFile

其他资源

执行独立存储任务