views:

292

answers:

2

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  A: 

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
Andréas Saudemont
What if the file is content from a referenced project or assembly? I can't find a way to access it using either Application.GetResourceStream or the relative Pack URI format...
Greg Bray
A: 

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.

Dennis Delimarsky
a hybrid approach would be best. if you go web-only, the app doesn't do anything at all if there's no network...
John Gardner
It really depends on what the app does. In this case, the applications needs Bing Maps anyway. So it won't work without an active Internet connection anyway. Therefore, a web-only approach here is appropriate.
Dennis Delimarsky
The problem that I have with downloading the list is that it's currently 940kb. And it will probably grow over time. That means that the first time you run the app it will download quite a big chunk of data. So I figured I store an initial list with the app and then download updates. The customers will probably prefer that.
Smetad Anarkist

related questions