v.g.
v.g.

Reputation: 1076

How to read a local xml file into a string

In the root of my solution I have a XML file, which content I want to write to a string, because later I parse this string. What is the easiest way in WP8. I dont want to parse anything, just my string to have the content of the xml file, then I use this string the way I do now. Or the file needs to be txt with xml inside, I dont care. Thanks!

Upvotes: 1

Views: 5720

Answers (2)

har07
har07

Reputation: 89305

You may want to try this :

StreamResourceInfo strm = Application.GetResourceStream(new Uri("/myProject;component/States.xml",UriKind.Relative)); 
StreamReader reader = new StreamReader(strm.Stream);
string xmlData = reader.ReadToEnd();

[Nokia developer community wiki: Parse Local XML file in Windows Phone]

or another possible way as shown in this other SO question : Windows Phone 8 - reading and writing in an existing txt file in the project

Upvotes: 1

Matthew Flynn
Matthew Flynn

Reputation: 3941

how about

using System.Xml.Linq;

// load the file using;
var xDocument = XDocument.Load(@"C:\MyFile.xml");
// convert the xml into string
string xml = xDocument.ToString();

Upvotes: 3

Related Questions