Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
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

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.
 
Share this answer
 
It's pretty simple:
C#
WebClient wc = new WebClient();
string html = wc.DownloadString(URL);
File.WriteAllText(path, html);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900