简体   繁体   中英

How can i read a .txt file from a website with WP7?

I'm working on my thesis project and I need to open and read a file from a website. I couldn't find anything. How can I do that?

Use WebClient . If you just want the contents as a string, it could be something like:

WebClient cli = new WebClient();
cli.DownloadStringCompleted += // your completed handler
cli.DownloadStringAsync(uri);

Because all network IO on WP7 is asynchronous, you have to attach an event handler and wait for the event to be raised before you get the data.

well,HttpRequest can reads the file,but i need to download the file before reading it,i need to change some variables inside the txt file

and this is the file that i download

http://dhmi.gov.tr/UcusBilgileri/1/domarr.txt

You can only IsolatedStorage for file IO in Windows Phone 7

For downloading the text file, the easiest way would probably to use the WebClient's DownloadString() method. Then write the contents of this file to the IsolatedStorage.

This might also interest you: http://weblogs.asp.net/gunnarpeipman/archive/2010/05/06/windows-phone-7-development-using-isolated-storage.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM