Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read a file from internet?

Tags:

c#

file

simple question: I have an file online (txt). How to read it and check if its there? (C#.net 2.0)

like image 901
PassionateDeveloper Avatar asked Mar 18 '10 15:03

PassionateDeveloper


People also ask

How do I read a file in a URL?

After you've successfully created a URL , you can call the URL 's openStream() method to get a stream from which you can read the contents of the URL. The openStream() method returns a java. io. InputStream object, so reading from a URL is as easy as reading from an input stream.

How do I read a file from a server?

A text file on a server can be read with Javascript by downloading the file with Fetch / XHR and parsing the server response as text. Note that the file needs be on the same domain. If the file is on a different domain, then proper CORS response headers must be present.


1 Answers

I think the WebClient-class is appropriate for that:  

WebClient client = new WebClient(); Stream stream = client.OpenRead("http://yoururl/test.txt"); StreamReader reader = new StreamReader(stream); String content = reader.ReadToEnd(); 

http://msdn.microsoft.com/en-us/library/system.net.webclient.openread.aspx

like image 71
Pbirkoff Avatar answered Sep 18 '22 18:09

Pbirkoff