该 IsolatedStorageFile 类提供两种用于删除独立存储文件的方法:
实例方法 Remove() 不采用任何参数并删除调用它的存储区。 此操作不需要任何权限。 任何可访问存储区的代码都可以删除其中的任何或所有数据。
静态方法 Remove(IsolatedStorageScope) 采用 User 枚举值,并删除运行代码的用户的所有存储。 该操作需要IsolatedStorageFilePermission权限以获取AdministerIsolatedStorageByUser值。
示例:
下面的代码示例演示如何使用静态和实例 Remove 方法。 该类获取两个存储区:一个是为用户和程序集隔离的,另一个是为用户、域和程序集隔离的。 然后,通过调用 Remove() 独立存储文件 isoStore1
的方法删除用户、域和程序集存储。 然后,通过调用静态方法 Remove(IsolatedStorageScope)删除用户的所有剩余存储。
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.
}
Imports System.IO.IsolatedStorage
Public Class DeletingStores
Public Shared Sub Main()
' Get a new isolated store for this user, ___domain, and assembly.
' Put the store into an IsolatedStorageFile object.
Dim isoStore1 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
IsolatedStorageScope.Domain Or IsolatedStorageScope.Assembly, Nothing, Nothing)
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.
Dim isoStore2 As IsolatedStorageFile = IsolatedStorageFile.GetStore(IsolatedStorageScope.User Or
IsolatedStorageScope.Assembly, Nothing, Nothing)
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 Sub
End Class