65.9K
CodeProject is changing. Read more.
Home

Get HTML Source of Webpage

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.33/5 (3 votes)

Oct 22, 2013

CPOL
viewsIcon

13912

downloadIcon

112

HTML source code of any website/webpage.

Introduction 

The article is regarding how to get the HTML source of any webpage without being redirected to a particular webpage.

Using the code

Go through the following code to know how to get the HTML source from any webpage without being redirected in ASP.NET:

static string GetHtmlPage(string strURL)
{
    String strResult;
    WebResponse objResponse;
    WebRequest objRequest = HttpWebRequest.Create(strURL);
    objResponse = objRequest.GetResponse();
    using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
    {
        strResult = sr.ReadToEnd();
        sr.Close();
    }
    return strResult;
}