1
votes

I just upgraded my Windows Phone 8.0 Silverlight app to a Windows Phone 8.1 Runtime app. Unfortunately, I have to downgrade this app to a 8.1 SL project, because Windows Runtime lacks Google Admob support.

That aside, in my 8.1 RT project I use the following code to fetch a XML feed:

private async void GetData()
{
    XmlDocument regenthetinXML = await XmlDocument.LoadFromUriAsync(new Uri("http://regenthet.in/data/regenthetin.xml", UriKind.Absolute));
}

The XmlDocument class is supported at both platforms, but when I use exactly the same code in my Windows Phone 8.1 SL project I get exceptions like this one:

An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.ni.dll but was not handled in user code

Additional information: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)

Any suggestions? What I'm doing wrong?

1
Take a look here at this previous SO posting looks to be similar in nature.. stackoverflow.com/questions/9650232/…MethodMan

1 Answers

0
votes

Use a WebClient to retrieve the string first.

string xmlStr;
string m_strFilePath = "http://regenthet.in/data/regenthetin.xml";
using(var wc = new WebClient())
{
    xmlStr = wc.DownloadString(m_strFilePath);
}
var xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xmlStr);

On mobile, if you don't have DownloadString, use DownloadStringAsync with an additional event handler to DownloadStringCompleted.