I have a windows store app. I have a XML file containing data. I need to add this file as resource of my app. I need to read data to XDocument from this file.
1) What build action I should set when add XML file to project? (I think this is "Content")
2) How to get XDocument object from this XML file?
After 2 hours I've got this code:
public static class DataLoader {
public static XDocument LoadFromXmlResource(string path){
path.Replace('\\', '/');
path.TrimEnd('/');
string uriPath = "ms-appx:///MyApp/" + path;
Task<StorageFile> operation = StorageFile.GetFileFromApplicationUriAsync(new Uri(uriPath)).AsTask<StorageFile>();
StorageFile file = operation.Result;
Task<string> fileReadingTask = FileIO.ReadTextAsync(file).AsTask<string>();
string fileContent = fileReadingTask.Result;
XDocument result = XDocument.Parse(fileContent, LoadOptions.None);
return result;
}
}
this works, but I'm not shure that it is correct.