Click here to Skip to main content
14,638,900 members
Rate this:
Please Sign up or sign in to vote.
See more:
I need to download the text content of a webpage and save it to a txt file using C#.

What I have tried:

I am a beginner in coding, I have googled and found someways to create and write a file using C#.But i couldn't get the c# tutorial for downloading a webpage into a txt file.
Posted
Updated 24-Mar-17 0:06am
v2
Rate this:
Please Sign up or sign in to vote.

Solution 2

See the WebClient.DownloadString Method (String) (System.Net)[^].
It gets the content of a web site into a string which can be written to a file.

But you should use the .htm or .html file extension because web sites are HTML. If you want the content of the web site as plain text, you have to use a HTML to text converter.
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

It's pretty simple:
WebClient wc = new WebClient();
string html = wc.DownloadString(URL);
File.WriteAllText(path, html);
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100