How to get the contents of a web page in C#?

Posted by SheoNarayan under C# category on | Views : 7941
Lets say you have a requirement where you need to get the actual code of a webpage into C#, you can do that easily with following code.

            string webPageToGet = "";
using (WebClient webClient = new WebClient())
string response = webClient.DownloadString(webPageToGet); // downloads the string and save into the response variables
Response.Write(response); // write the webpage contents

The above code will get the actual html code of the and save into response variable. You can either write it or use in whatever way you want to use.

Comments or Responses

Login to post response