无法序列化为xml文件 [英] Can't serialize to xml File

查看:79
本文介绍了无法序列化为xml文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 XmlSerializer xS = new XmlSerializer(myProfile.GetType()); 
StreamWriter sW = new StreamWriter(" /myProfile.xml");
xS.Serialize(sW.BaseStream,myProfile);

亲爱的Windows手机开发社区,



我对此代码有疑问。


我想将对象保存在XML文件中。


我想写的XML文件位于同一个Project中,他总是说异常"'System.UnauthorizedAccessException"。



感谢您的帮助。












解决方案

在Windows Phone中,您必须将文件保存在独立存储中。尝试以下链接中的代码


http://www.geekchamp.com/tips/all-about-wp7-isolated-storage---read-and-save-xml-files

http://blogs.msdn .com / b / dawate / archive / 2010/08/31 / windows-phone-7-xml-isolatedstorage-example.aspx


XmlSerializer xS = new XmlSerializer(myProfile.GetType());
            StreamWriter sW = new StreamWriter("/myProfile.xml");
            xS.Serialize(sW.BaseStream, myProfile);

Dear Windows phone dev community,

i have a Problem with this code.

I want to save the object in a XML file.

The XML file to which I want to write is in the same Project and he always says that exception "'System.UnauthorizedAccessException".

Thanks for your help.

解决方案

In Windows Phone you have to save the file in Isolated Storage. Try code in following links

http://www.geekchamp.com/tips/all-about-wp7-isolated-storage---read-and-save-xml-files
http://blogs.msdn.com/b/dawate/archive/2010/08/31/windows-phone-7-xml-isolatedstorage-example.aspx


这篇关于无法序列化为xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆