快速理解WP7的Isolated Storage

这篇文章很好的介绍了Isolated Storage。取其精华作为以后参考。

Isolated Storage的结构

示例代码如下:

  
    
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
string text;
if (IsolatedStorageSettings.ApplicationSettings.TryGetValue( " text " , out text))
{
this .textBox1.Text = text;
}

var fileStorage
= IsolatedStorageFile.GetUserStoreForApplication();
if (fileStorage.FileExists( " text.txt " ))
{
using (var fin = new StreamReader( new IsolatedStorageFileStream( " text.txt " , FileMode.Open, fileStorage)))
{
this .textBox2.Text = fin.ReadToEnd();
}
}
}

private void button1_Click( object sender, RoutedEventArgs e)
{
IsolatedStorageSettings.ApplicationSettings[
" text " ] = textBox1.Text;
}

private void button2_Click( object sender, RoutedEventArgs e)
{
var fileStorage
= IsolatedStorageFile.GetUserStoreForApplication();
using (var writer = new StreamWriter( new IsolatedStorageFileStream( " text.txt " , FileMode.OpenOrCreate, fileStorage)))
{
writer.Write(textBox2.Text);
}
}

 

你可能感兴趣的:(ora)