0

What is wrong here? It throws ArgumentException

var xmlDocument = await XmlDocument.LoadFromUriAsync(new Uri("ms-appx:///LiveTiles/Templates.xml"));

Is there more simple way to load XML from file?

Thank you!

splash27
  • 2,057
  • 6
  • 26
  • 49

1 Answers1

1

Windows RT is a little bit special at the time of manipulating files, I highly recommend this blog entry:

http://blog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html

Taken from the link:

// settings
// same as (ms-appx:///MyFolder/MyFile.txt)
var _Folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
_Folder = await _Folder.GetFolderAsync("MyFolder");

// acquire file
var _File = await _Folder.GetFileAsync("MyFile.txt");
Assert.IsNotNull(_File, "Acquire File");

// write content
var _WriteThis = "Hello World";
await Windows.Storage.FileIO.WriteTextAsync(_File, _WriteThis);

Or to simplify it a little bit more, another approach can be:

try

{

    StorageFolder storageFolder = Package.Current.InstalledLocation;

    StorageFile storageFile = await storageFolder.GetFileAsync("BasicData.xml");



    XmlTextBlock.Text = await FileIO.ReadTextAsync(storageFile, Windows.Storage.Streams.UnicodeEncoding.Utf8);



}

catch (Exception ex)

{

    XmlTextBlock.Text = ex.Message;

}
Nahuel Ianni
  • 3,177
  • 4
  • 23
  • 30