Windows phone IsolatedStorageFile 读写XML
来源:互联网 发布:世界经济数据 编辑:程序博客网 时间:2024/06/10 12:55
using System;using System.IO;using System.IO.IsolatedStorage;using System.Xml;using System.Xml.Serialization;namespace CommonUI.CommonHelper{ public static class IsolatedStorageFileHelper { private const string CONFIG_NAME = "Config.xml"; private static bool CheckStoreConfigExist() { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { return isolatedStorage.FileExists(CONFIG_NAME); } } /// <summary> /// Save data to XML file /// </summary> /// <typeparam name="T">the type to save</typeparam> /// <param name="t">the data the save</param> public static void CreateStoreConifgXML<T>(T t) { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { // Write to the Isolated Storage XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; if (CheckStoreConfigExist()) { isolatedStorage.DeleteFile(CONFIG_NAME); } using (IsolatedStorageFileStream isoStream = isolatedStorage.CreateFile(CONFIG_NAME)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); using (XmlWriter xmlWriter = XmlWriter.Create(isoStream, settings)) { serializer.Serialize(xmlWriter, t); } } } } /// <summary> /// Read data from config /// </summary> /// <typeparam name="T">the type to get</typeparam> /// <returns>the data get</returns> public static T GetDataFromConifgXML<T>(T t) { T result = default(T); try { using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication()) { if (!CheckStoreConfigExist()) { return result; } using (IsolatedStorageFileStream isoStream = isolatedStorage.OpenFile(CONFIG_NAME, FileMode.Open)) { using (StreamReader reader = new StreamReader(isoStream)) { XmlSerializer serializer = new XmlSerializer(typeof(T)); result = (T)serializer.Deserialize(reader); } } } } catch (Exception isoException) { //Nothing to do, only to prevent app crash here. } return result; } }}
0 0
- Windows phone IsolatedStorageFile 读写XML
- 独立存储, windows phone IsolatedStorageFile
- wp8 IsolatedStorageFile XML读写方法
- Windows Phone 独立存储之IsolatedStorageFile
- IsolatedStorageFile 本地数据缓存 xml dataset 读写
- Windows Phone的本地存储——IsolatedStorageFile
- windows phone:通过XmlSerializer读写XML文件
- Windows Phone的XML文件读写
- Windows phone 7中,把页面数据存为长期存储(非IsolatedStorageFile),而是用IsolatedStorageSettings
- silverlight IsolatedStorageFile 创建及操作xml
- windows下xml的读写
- windows mobile 如何读写XML文档 1
- [Windows通用应用开发] 读写XML文件
- windows phone:在xml中引用外部dll类
- windows phone
- Windows phone
- Windows Phone开发之独立存储、文件的读写、ListBox绑定数据、NavigationService实现XAML跳转
- Windows Phone中Stream和Buffer类读写操作(不仅仅是文本文件)
- 博客 第一篇
- HOOK专题[来自微软中国社区]
- SQL SERVER2008定期删除备份文件、备份
- Android Fragment之间的点击切换
- How to check permissions at runtime without throwing SecurityException?
- Windows phone IsolatedStorageFile 读写XML
- 网页视频播放方案-jaris flv player和ckplayer
- 最小二乘法
- Opencv在Crotex-A8的移植(pcduino)
- Direct3D 10教程7:纹理映射和常量缓存
- 代码访问 SQL Server数据库时的错误: 由于系统缓冲区空间不足或队列已满,不能执行套接字上的操作
- Deep Learning模型之:Sparse AutoEncoder
- [linux]ubuntu 新建用户及相关问题
- 快速排序算法