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.
}
预见空间不足的情况
使用独立存储的代码受配额的限制,该配额指定独立存储文件和目录所在的数据舱的最大大小。该值由安全策略确定,管理员可以对其进行配置。如果试图写入数据时超过了所允许的最大大小,将引发 IsolatedStorageException,并使操作失败。这有助于防止恶意的抵制服务攻击,受到这种攻击后会因为数据存储被填满而导致应用程序拒绝请求。为了帮助您确定给定的写入尝试是否会因为此原因而失败,独立存储提供了两个只读属性:IsolatedStorage.CurrentSize 和 IsolatedStorage.MaximumSize。这两个属性可用于确定写入存储区是否将导致超过存储区所允许的最大大小。当您使用这些属性时,请记住独立存储可能被同时访问;因此,如果您计算的存储量有剩余,则该存储空间可能在您试图写入存储区时已被使用。但是,这不会妨碍您使用存储区的最大大小来确定是否将达到可用存储的上限。
另一个重要的考虑是最大大小属性取决于来自正常工作的程序集的证据。因此,只应该对使用 GetUserStoreForAssembly()、GetUserStoreForDomain() 或 GetStore() 创建的 IsolatedStorageFile 对象调用此方法。以其他任何方式(例如从 GetEnumerator() 中返回)创建的 IsolatedStorageFile 对象将无法返回准确的最大大小。
AnticipatingOutOfSpaceConditions 示例
下面的代码示例获得一个独立存储区,创建几个文件并度量存储区中剩余的空间。以字节数报告剩余的空间。
[C#]
using System;
using System.IO;
using System.IO.IsolatedStorage;
public class CheckingSpace{
public static void Main(){
// Get an isolated store for this assembly and put it into an
// IsolatedStoreFile object.
IsolatedStorageFile isoStore =IsolatedStorageFile.GetStore(IsolatedStorageScope.User
关键词:运用 .NET的IO(4) Paul_Ni(原作)