独立存储设置IsolatedStorageSetting

 1 private IsolatedStorageSettings _appSettings;
 2 
 3 public MainPage()
 4 {
 5 InitializeComponnent();
 6 _appSettings=IsolatedStorageSettings.ApplicationSettings;
 7 }
 8 
 9 if (_appSettings.Contains(key))
10 {
11 _appSettings[key]=value;
12 }else{
13 _appSettings.Add(key,value);
14 }
15 _appSettings.Save();
16 
17 
18 
19 //删除
20 _appsettings.Remove(key);
21 
22 //清空
23 _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();//关闭手机本地存储流        

 

posted on 2014-12-21 01:34  - 物是人非#  阅读(201)  评论(0)    收藏  举报