Silverlight独立存储之读写文本文件

来源:互联网 发布:淘宝店铺客服怎么服务 编辑:程序博客网 时间:2024/05/02 09:26

Silverlight独立存储之读写文件

(2012-04-16 23:38:03)
引用
using System.IO;
using System.IO.IsolatedStorage;

激发按钮事件 写入
private boid button_Click(object sender,System.Windows.RotedEventArgs e){
if(this.textbox.Text=="" || this.passwordbox.Password==""){
MessageBox.Show("缺少输入信息");
}
IsolatedStorageFileStream isoStore=new IsolatedStorageFileStream("myinfo.txt",FileMode.Create,IsolatedStorageFile.GetUserStoreForApplication());
StreamWriter wtxt=new StreamWriter(isoStore);
wtxt.WriteLine(this.textbox.Text.Trim());
wtxt.WriteLine(this.passwordbox.Password.Trim());
wtxt.Close();
isoStore.Close();
MessageBox.Show("独立存储吸入myinfo.txt完成!");
}

激发按钮事件 读出
private boid buttonread_Click(object sender,System.Windows.RotedEventArgs e){
this.textblock.Text="";
if(!IsolatedStorageFile.GetUserStoreForApplication().FileExists("myinfo.txt")){
MessageBox.Show("没有可用的独立存储文件!");
}
IsolatedStorageFileStream isoStore=new IsolatedStorageFileStream("myinfo.txt",FileMode.Open,IsolatedStorageFile.GetUserStoreForApplication());
StreamReader rtxt=new StreamReader(isoStore);
this.textblock.Text=rtxt.ReadLine();
this.textblock.Text+="\r\n";
this.textblock.Text+=rtxt.ReadLine();
rtxt.Close();
isoStore.Close();
}
点击打开链接
http://blog.sina.com.cn/s/blog_7131d05a01012llv.html
原创粉丝点击