Adding files to WP7 isolated storage from Visual Studio?

一个人想着一个人 提交于 2019-11-30 17:31:08

问题


I'm working on an Windows Phone 7 app where I'm going to show ATM's nere your location with bing maps.

I have an xml-file with addresses and gps coordinates. But how do I add this file to my program from visual studio? If I set BuildAction to Content and Copy to output directory to Copy always. The file still isn't in IsolatedStorage. Do I have to build a mechanism to download the information from the web? Or is there another way?


回答1:


You cannot directly pass files to the isolated storage at design time. Only when the application is running.

I'd still recommend passing the file to the application through a web service. Mainly because if eventually you will need to change the contents of the XML, you will need to update the application.

What I would do is simply create a WCF service that will return serialized data (or the existing XML) via a simple HTTP request.




回答2:


Files listed as content in the Visual Studio project are copied to the generated XAP file (which is analogous to a ZIP file). They are not copied to isolated storage.

In the case of an XML file, you can call XmlReader.Create with the path to the file as argument, as follows:

using (XmlReader reader = XmlReader.Create("path/to/file.xml"))
{
    // read XML file here
}

Or you can also call Application.GetResourceStream and use the Stream property of the returned StreamResourceInfo object:

StreamResourceInfo sri = Application.GetResourceStream(
    new Uri("path/to/file.xml", UriKind.Relative));
// read XML file here from sri.Stream, e.g. using a StreamReader object



回答3:


The "Mango" SDK ships with the ISETool that can take and restore snapshots of an application's isolated storage to/from a local directory:

# Copy data from IS to directory
ISETool.exe ts xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"

# Copy data from IS to directory
ISETool.exe rs xd <PRODUCT-ID> "C:\TempDirectory\IsolatedStore"

If you don't want to overwrite the entire IS, the tool supports an option (device-folder) for specifying a sub-directory to backup/restore.



来源:https://stackoverflow.com/questions/3690815/adding-files-to-wp7-isolated-storage-from-visual-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!