Windows Phone 学习笔记(一) 数据存储
2014-12-21 01:34
197 查看
独立存储设置IsolatedStorageSetting
独立存储文件IsolatedStorageFile
调用手机的独立存储
IsolatedStorageFile storage=IsolatedStorageFile.GetUserStoreForApplication();
创建独立存储文件流
IsolatedStorageFilStream location=new IsolatedStorageFileStream(fileName,System.IO.FileMode.Create,storage);
读写该文件流
System.IO.StreamWriter file=new System.IO.StreamWriter(location);
将XML文件保存到流file觞,_doc是用户创建的文件
_doc.Save(file);
private IsolatedStorageSettings _appSettings; public MainPage() { InitializeComponnent(); _appSettings=IsolatedStorageSettings.ApplicationSettings; } if (_appSettings.Contains(key)) { _appSettings[key]=value; }else{ _appSettings.Add(key,value); } _appSettings.Save(); //删除 _appsettings.Remove(key); //清空 _appSettings.Clear();
独立存储文件IsolatedStorageFile
调用手机的独立存储
IsolatedStorageFile storage=IsolatedStorageFile.GetUserStoreForApplication();
创建独立存储文件流
IsolatedStorageFilStream location=new IsolatedStorageFileStream(fileName,System.IO.FileMode.Create,storage);
读写该文件流
System.IO.StreamWriter file=new System.IO.StreamWriter(location);
将XML文件保存到流file觞,_doc是用户创建的文件
_doc.Save(file);
XDocument _doc = new XDocument(); XElement _item = new XElement(nameTxt.Text);//创建一个XML元素 XAttribute price = new XAttribute("price", priceTxt.Text);//创建一个XML属性 XAttribute quantity = new XAttribute("quantity", quanTxt.Text); _item.Add(price, quantity);//将这两个属性添加到 XML元素上 //用_item 新建一个XML的Linq文档 _doc = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), _item); //创建一个本地存储的文件流 IsolatedStorageFileStream location = new IsolatedStorageFileStream(nameTxt.Text + ".item", System.IO.FileMode.Create, storage); //将本地存储文件流转化为可写流 System.IO.StreamWriter file = new System.IO.StreamWriter(location); //将XML文件 保存到流file上 即已经写入到手机本地存储文件上 _doc.Save(file); file.Dispose();//关闭可写流 location.Dispose();//关闭手机本地存储流
相关文章推荐
- Windows Phone 7 学习笔记:数据存储与获取的方式介绍
- SilverLight学习笔记--本地(客户端)数据存储
- Redis学习笔记4--Redis数据存储优化机制
- 学习笔记 第7章 数据存储与访问
- Windows phone 8 学习笔记(2) 数据文件操作(转)
- c语言学习笔记_数据格式_int与char的存储方式小节
- Android 学习笔记7---数据存储与访问
- 【Cocos2d-X开发学习笔记】第29期:游戏中数据的存储(上)
- Windows phone 8 学习笔记(2) 数据文件操作
- 【Cocos2d-X开发学习笔记】第30期:游戏中数据的存储(下)
- cocos2d-x 3.1.1 学习笔记[14] UserDefault 用户数据存储
- Windows 8学习笔记(四)--Storage数据存储
- 【OpenCV学习笔记】之三:Mat初始创建方法----要求数据连续存储
- Windows Phone 开发学习笔记(十) RSS阅读器之解析数据
- Android入门学习笔记(一)|基础知识|文件数据存储读取|解析XML
- Chap 4 学习笔记-使用C#存储变量数据
- Windows 8学习笔记(四)--Storage数据存储
- Windows Phone 开发学习笔记(十一) RSS阅读器之显示数据
- iOS学习笔记3—NSKeyedUnarchiver进行本地数据的读取|存储
- IOS学习笔记 -- Segue、数据存储、UITabBarController