Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file from URL to a string

Tags:

c#

How could I use C# to download the contents of a URL, and store the text in a string, without having to save the file to the hard drive?

like image 258
Chiggins Avatar asked Jul 12 '10 20:07

Chiggins


People also ask

How to download URL to file or string in C #?

The easiest way to download an URL to file or string in C# is using the System.Net.WebClient class. Download URL to file using WebClient class:

What is the difference between downloadstring (Uri) and downloadstring?

The resource to download is specified as a Stringcontaining the URI. DownloadString(Uri) Downloads the requested resource as a String. The resource to download is specified as a Uri. DownloadString(String) Downloads the requested resource as a String.

What is the use of downloadstring in Java?

DownloadString(String) Downloads the requested resource as a String. The resource to download is specified as a Stringcontaining the URI. public: System::String ^ DownloadString(System::String ^ address); public string DownloadString (string address); member this.DownloadString : string -> string

How do I download a file from a URL in Python?

To download a file from a URL, we can use this one-liner: FileUtils.copyURLToFile (new URL (FILE_URL), new File (FILE_NAME), CONNECT_TIMEOUT, READ_TIMEOUT); From a performance standpoint, this code is the same as the one we've exemplified in section 2.


1 Answers

string contents; using (var wc = new System.Net.WebClient())     contents = wc.DownloadString(url); 
like image 75
mmx Avatar answered Sep 28 '22 15:09

mmx