A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

李树明

中级黑马

  • 黑马币:0

  • 帖子:15

  • 精华:0

© 李树明 中级黑马   /  2012-3-5 11:05  /  1779 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 李树明 于 2012-3-13 14:06 编辑

Wp7中,怎么实现数据长期存储?

评分

参与人数 2技术分 +1 黑马币 +5 收起 理由
lsmlsm + 5
郑文 + 1

查看全部评分

2 个回复

倒序浏览
http://topic.csdn.net/t/20020718/07/882679.html
回复 使用道具 举报
刚才的发错呢。
我用的是将数据保存在文件中:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.IO.IsolatedStorage;
using System.IO;
using System.Xml;
using System.Collections.Generic;
using System.Xml.Serialization;
namespace NoteText
{
    public class XmlMessage
    {
        //using System.Collections.Generic 对应list
        //将对象写入xml文档中
        public void WriteMessage(List<Item> itemslist)
        {
            var isoFile = IsolatedStorageFile.GetUserStoreForApplication();
            string filePath = System.IO.Path.Combine("note", "note.xml");
            if (!isoFile.DirectoryExists("note"))
            {
                isoFile.CreateDirectory("note");

            }
            FileStream fs = isoFile.CreateFile(filePath);
            fs.Close();

            XmlWriterSettings xmlWriterSetting = new XmlWriterSettings();
            xmlWriterSetting.Indent = true;
            using (IsolatedStorageFile myIsolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedStorageFileStream stream = myIsolatedStorage.OpenFile(filePath, FileMode.Create))
                {
                    XmlSerializer xmlSerializer = new XmlSerializer(typeof(List<Item>));
                    using (XmlWriter xmlWriter = XmlWriter.Create(stream, xmlWriterSetting))
                    {
                        xmlSerializer.Serialize(xmlWriter, itemslist);
                    }
                }
            }
        }

        // //读取xml文档的内容
        public List<Item> ReadMessage()
        {
            List<Item> itemlist;
            using (IsolatedStorageFile myIsolatedStorageFile=IsolatedStorageFile.GetUserStoreForApplication())
            {
                 string filePath = System.IO.Path.Combine("note", "note.xml");
                using (IsolatedStorageFileStream stream =myIsolatedStorageFile.OpenFile (filePath,FileMode .Open ))
                {
                    XmlSerializer serializer = new XmlSerializer(typeof (List<Item>));
                    itemlist = (List<Item>)serializer.Deserialize(stream);
                }
            }
            return itemlist;
        }

    }
}
Item是自己定义的类
不知道对你有用处吗?
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马