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.
Check the HttpWebRequest Class. This video should help you also.
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
精彩评论