隔离存储总是必要的吗? [英] Is Isolated Storage Always Necessary?

查看:29
本文介绍了隔离存储总是必要的吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到了很多关于如何将数据从应用程序写入文件然后将其放入独立存储的示例.我不想将任何数据写入我的 xml 文件,我只是想将其保存到独立存储中,然后稍后再查询.

I see alot of examples on how to write data from an app to a file then put it in isolated storage. I do not want to write any data to my xml file, I just simply want to save it into isolated storage then query it later.

几个简单的问题

  • 有人有关于如何将现有 xml 文件放入隔离存储的代码.此外,由于我没有写入此文件,我还需要隔离存储吗?我可以将 xml 添加到我的项目中并使用 Linq to xml 打开它查询它并在单击按钮时关闭它吗?

  • Someone have code on how to put an existing xml file into isolated storage. Also since I am not writing to this file, do I need isolated storage still? Can I just add the xml to my project and use Linq to xml to open it query it and close it on a button click?

我想在后台通过我的应用程序查询 xml.我看到很多关于序列化的例子,我需要这样做吗?可以直接打开xml文件用linq to xml查询数据吗?

I wanna query the xml through my application in the background. I see alot of examples on serializing, do I need to do this? Can I just open the xml file and use linq to xml to query the data?

我可以这样做吗,将 bbxml.xml 设置为 Content 而忘记隔离存储就这样做吗?

Can I just do this, set bbxml.xml to Content and forget about isolated storage and just do this?

 using (XmlReader reader = XmlReader.Create("bbxml.xml"))
        {
            XDocument xml = XDocument.Load(reader);
            //query xml....
}

推荐答案

在 Visual Studio 的项目文件中包含 XML 文件,然后在属性"窗口中确保将 Build Action 设置为 ContentCopy to Output Directory 设置为 Copy alwaysCopy if newer.这将在输出 XAP 文件中包含该文件.

Include the XML file in your project files in Visual Studio, then in the Properties window make sure Build Action is set to Content and Copy to Output Directory is set to Copy always or Copy if newer. This will include the file in the output XAP file.

要在代码中访问此文件,请使用:

To access this file in code use:

XDocument doc = XDocument.Load( "path/to/my/file.xml" );

当然,它不一定是XDocument,您可以类似地使用任何 XML 阅读器类.

Of course, it doesn't have to be XDocument, you can use any XML reader class similarly.

这篇关于隔离存储总是必要的吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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