//独立存储库(Isolated Storage),它是硬盘的一个分区,如果你在硬盘上执行搜索并包含隐藏文件,你找不到
//在此库中创建的文件.
private static void RWStorage()
{
IsolatedStorageFile isoStore;
isoStore=IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.User ,null ,null); //|| IsolatedStorageScope.User
string[] FileNames=isoStore.GetFileNames("mySecretStuff.secret") ;
DateTime installDate=DateTime.Now ;
if(FileNames.Length ==0)
{
//创建一个新的 存储文件
StreamWriter writer =new StreamWriter(new IsolatedStorageFileStream("mySecretStuff.secret" ,FileMode.CreateNew ,isoStore));
writer.WriteLine(DateTime.Now ) ;
writer.WriteLine("mrfu");
writer.Close();
}
else
{
StreamReader reader=new StreamReader( new IsolatedStorageFileStream("mySecretStuff.secret" ,FileMode.Open ,isoStore));
string tempStr=reader.ReadLine();
string myName=reader.ReadLine();
installDate=DateTime.Parse(tempStr);
MessageBox.Show(tempStr+"\n"+myName) ;
}
DateTime dateExpires=installDate.AddDays(60) ;
System.TimeSpan diff1 ;
diff1 = dateExpires.Subtract(DateTime.Now );
MessageBox.Show(dateExpires.ToShortDateString()+"\n"+diff1.Days.ToString() ) ;
}
//在此库中创建的文件.
private static void RWStorage()
{
IsolatedStorageFile isoStore;
isoStore=IsolatedStorageFile.GetStore(IsolatedStorageScope.Assembly | IsolatedStorageScope.User ,null ,null); //|| IsolatedStorageScope.User
string[] FileNames=isoStore.GetFileNames("mySecretStuff.secret") ;
DateTime installDate=DateTime.Now ;
if(FileNames.Length ==0)
{
//创建一个新的 存储文件
StreamWriter writer =new StreamWriter(new IsolatedStorageFileStream("mySecretStuff.secret" ,FileMode.CreateNew ,isoStore));
writer.WriteLine(DateTime.Now ) ;
writer.WriteLine("mrfu");
writer.Close();
}
else
{
StreamReader reader=new StreamReader( new IsolatedStorageFileStream("mySecretStuff.secret" ,FileMode.Open ,isoStore));
string tempStr=reader.ReadLine();
string myName=reader.ReadLine();
installDate=DateTime.Parse(tempStr);
MessageBox.Show(tempStr+"\n"+myName) ;
}
DateTime dateExpires=installDate.AddDays(60) ;
System.TimeSpan diff1 ;
diff1 = dateExpires.Subtract(DateTime.Now );
MessageBox.Show(dateExpires.ToShortDateString()+"\n"+diff1.Days.ToString() ) ;
}