How to load XML file that is stored on my laptop from HTTPS using WebClient/HTTPWebRequest - WP7
I need to load an xml file, that is stored in my laptop, on a WP7 application. I have used the code that I found on a similar topic:
private void button2_Click(object sender, RoutedEventArgs e) { WebClient wc = new WebClient(); wc.DownloadStringCompleted += HttpsCompleted; wc.DownloadStringAsync(new Uri("https://domain/path/file.xml")); }
private void HttpsCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
XDocument xdoc = XDocument.Parse(e.Result, LoadOptions.None);
this.textBox1.Text = xdoc.FirstNode.ToString();
}
}
The path to the file I need to load is C:\test.xml
So what do i need to fill in the Uri?
I tried something like the following : "htt开发者_运维问答ps://localhost/C:/test.xml" but doesnt work
Anyone can help me ?
You can't access the file system on PCs directly in this way.
You'd need to have a http service of some kind running on the laptop to server the file(s) you want.
A similar project was published during CTP that you might like to check out (will likely need some updating to work with current tooling, or you can just review the code for ideas).
Rongchaua's blog » Windows Phone – Phone PC Connector through WCF service
I guess you just want to include an XML file to your WP7 application. This link may help you to have your Data(XML) associate with your WP7 app. Though it is Silverlight the code works for WP7 also.
http://jobijoy.blogspot.com/2009/03/different-ways-to-access-xml-data-in.html
What are you using as a webserver? If it's cassini the default server used by VS then it doesn't support HTTPS.
if you're trying to connect from the emulator or tethered device then why are you bothering with HTTPS? What extra security do you need in the communication between 2 directly connected systems?
have you got a webserver running on your local machine? If not you'll need to set one up and copy the file in question to somewhere that the website/service has access to.
Finally, check the certificate you are using to connect over SSL is trusted by the device.
Edit:
There is no way to get the file from your PC at runtime without a HTTP based request.
By using a HTTP request (as you are in your example) you don't have direct access to the file system in the way you are attempting.
If this is a file you want to include with your application then you should be including it as part of the project.
It's not clear from your question if this is the same file you always want in your application or if the intetion is to use different files at runtime.
精彩评论