详解Silverlight 2中的独立存储(Isolated Storage)
2008-10-09 11:38:47 来源:WEB开发网void btnReadFile_Click(object sender, RoutedEventArgs e)
{
if (this.lstDirectories.SelectedItem == null ||
this.lstFiles.SelectedItem == null)
{
HtmlPage.Window.Alert("请先选择目录和文件!");
return;
}
using (IsolatedStorageFile store =
IsolatedStorageFile.GetUserStoreForApplication())
{
String filePath = System.IO.Path.Combine(this.lstDirectories.SelectedItem.ToString(),
this.lstFiles.SelectedItem.ToString());
if (store.FileExists(filePath))
{
StreamReader reader = new StreamReader(store.OpenFile(filePath,
FileMode.Open, FileAccess.Read));
this.txtFileContent.Text = reader.ReadToEnd();
this.txtDirectoryName.Text = this.lstDirectories.SelectedItem.ToString();
this.txtFileName.Text = this.lstFiles.SelectedItem.ToString();
}
}
}
删除目录和文件:
void btnDeleteFile_Click(object sender, RoutedEventArgs e)
{
if (this.lstDirectories.SelectedItem != null &&
this.lstFiles.SelectedItem != null)
{
using (IsolatedStorageFile store =
IsolatedStorageFile.GetUserStoreForApplication())
{
String filePath = System.IO.Path.Combine(this.lstDirectories.SelectedItem.ToString(),
this.lstFiles.SelectedItem.ToString());
store.DeleteFile(filePath);
HtmlPage.Window.Alert("删除文件成功!");
}
}
}
void btnDeleteDirectory_Click(object sender, RoutedEventArgs e)
{
if (this.lstDirectories.SelectedItem != null)
{
using (IsolatedStorageFile store =
IsolatedStorageFile.GetUserStoreForApplication())
{
store.DeleteDirectory(this.lstDirectories.SelectedItem.ToString());
HtmlPage.Window.Alert("删除目录成功!");
}
}
}
获取目录列表和文件列表:
Tags:详解 Silverlight 独立
编辑录入:爽爽 [复制链接] [打 印]- ››详解Windows XP中可以被禁用的服务
- ››独立博客建设之规划篇:5W定位法(Who)
- ››独立博客建设之规划篇:5W定位法(What)
- ››详解教育类网站的三种赢利模式
- ››详解Windows 7 SP1新增功能
- ››详解XML各种解析方法
- ››详解PHP异常机制的流程及原理
- ››Silverlight for Windows Phone 7开发系列(1):...
- ››Silverlight for Windows Phone 7开发系列(2):...
- ››Silverlight for Windows Phone 7开发系列(3):...
- ››Silverlight for Windows Phone 7开发系列(4):...
- ››详解ISA2006防火墙三种客户端代理与配置
更多精彩
赞助商链接