如何在Windows 8应用程序中序列化几次

时间:2013-12-04 19:48:01

标签: c# windows serialization deserialization

嗨,我尝试了一切:D 我在Windows应用程序中尝试反序列化file.xml几次时遇到问题。求助于帮助:) Windows 8应用程序 当我有菜单时,我有MainPage

  1. 有人选择“显示数据”
  2. 继续“dataPage”
  3. 我反序列化plik.xml,显示数据,app显示数据,everthing很好
  4. 我回到MainPage,我想再次显示来自同一个文件的数据,但现在我什么都不读,我的意思是'单词不包含数据

                  DESERIALIZATION
       StorageFile sessionFile;
    
        var serializer = new XmlSerializer(typeof(List<word>));
        words = new List<word>();
    
        try
        {
            if (await XMLModifier.IsFileExists(XMLModifier.wordsContainter, ApplicationData.Current.LocalFolder) == true)
            {
                sessionFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(XMLModifier.wordsContainter, CreationCollisionOption.OpenIfExists);
                IInputStream sessionInputStream = await sessionFile.OpenReadAsync();
                words = (List<word>)serializer.Deserialize(sessionInputStream.AsStreamForRead());
                sessionInputStream.Dispose();
            }
            else
            {
                string data = DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year;
                word w = new word("Base is empty", "Base is empty", data, 0, 0, 0);
                words.Add(w);
            }
        }
        catch (Exception e)
        {
            ..............
        }
    

0 个答案:

没有答案