views:

40

answers:

1

I do not want to load it from a website I have added it to my project all I want to do is access it and read it. Can anyone help!

+2  A: 

I've found a blog post by Mike Snow which describes one method. The code's a bit long to quote in full, but here's the relevant section:

StringReader stream = new StringReader(e.Result);
XmlReader reader = XmlReader.Create(stream);

while (reader.Read())
{
    // Do stuff
}

The xml file is downloading using this code:

Uri url = new Uri("MapImages.xml", UriKind.Relative);
WebClient client = new WebClient();
client.DownloadStringCompleted +=
        new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
client.DownloadStringAsync(url);

From the DownloadStringAsync MSDN page:

After downloading the resource, this method uses the encoding specified in the Encoding property to convert the resource to a String. This method does not block the calling thread while downloading the resource. To download a resource and block while waiting for the server's response, use the DownloadString method. When the download completes, the DownloadStringCompleted event is raised. Your application must handle this event to receive notification. The downloaded string is available in the Result property.

So it downloads the file to your temporary internet files folder (or cache depending on browser) and then passes the file as a string to the event handler, where you can read it using StringReader.

ChrisF
Doesn't the Uri and WebClient go out to the website and download the XML file to the user's machine?
cbleile
@cbeile - Yes, but only as a temporary file
ChrisF