您的位置:首页 > 其它

windows phone 独立存储空间的操作 (2)

2012-03-25 12:29 369 查看
IsolatedStorage独立存储空间是保存应用程序的一些数据已经配置文件,独立存储空间相对于其他的wp程序是独立的,也就是说每个wp程序都会有自己的独立存储空间,每个wp程序相互之间不能访问;

什么是Isolated Storage?

Isolated Storage又叫做隔离存储空间,Windows Phone 7手机上用来本地存储数据。下图是一个存储应用的文件夹结构图:

View Code /// <summary>
/// 读操作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnRead_Click(object sender, RoutedEventArgs e)
{
IsolatedStorageFile isStore = IsolatedStorageFile.GetUserStoreForApplication();

if (isStore.FileExists("test\\TEST.txt"))
{
IsolatedStorageFileStream isStream = new IsolatedStorageFileStream("test\\TEST.txt", System.IO.FileMode.Open, FileAccess.Read, isStore);
//获取路径
string[] directoryName = isStore.GetDirectoryNames("test");
//获取文件名 搜索模式。 单字符("?")和多字符("*")通配符都受支持
string[] fileName = isStore.GetFileNames("test\\T*.txt");
txtShow.Text = "写入资料值为:" + isStream.ReadByte().ToString() + ";\n路径为:" + directoryName[0].ToString() + ";\n文件名称为:" + fileName[0];

isStream.Close();
isStore.Dispose();
txtShow.Text =txtShow.Text+ "\n读取完成";
//存储配置信息
var settings = IsolatedStorageSettings.ApplicationSettings;

//判断key 是否存在
if (settings.Contains("ip"))
{
//只支持key的查询
string ip = settings["ip"].ToString();
//out传参获取值
string ipStr;
settings.TryGetValue("ip", out ipStr);
txtShow.Text = txtShow.Text + "\n配置文件ip:" + ip + ";\n out传参ip:"+ipStr;

}

}
}

读取效果

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: