Click here to Skip to main content
15,886,258 members
Articles / Web Development / ASP.NET
Tip/Trick

Get HTML Source of Webpage

Rate me:
Please Sign up or sign in to vote.
2.33/5 (3 votes)
22 Oct 2013CPOL 13.2K   105   7   9
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:

C#
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;
}

License

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


Written By
Software Developer (Junior) Smart Solutions
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionWorks perfect, and fast Pin
B. Clay Shannon28-Oct-13 9:09
professionalB. Clay Shannon28-Oct-13 9:09 
AnswerRe: Works perfect, and fast Pin
Dipesh Wadhwa29-Oct-13 0:11
Dipesh Wadhwa29-Oct-13 0:11 
GeneralMy vote of 1 Pin
Ted Goulden28-Oct-13 8:31
Ted Goulden28-Oct-13 8:31 
QuestionBe nice to show a complete example Pin
Ivor O'Connor22-Oct-13 8:54
Ivor O'Connor22-Oct-13 8:54 
AnswerRe: Be nice to show a complete example Pin
Dipesh Wadhwa23-Oct-13 23:45
Dipesh Wadhwa23-Oct-13 23:45 
GeneralRe: Be nice to show a complete example Pin
Ivor O'Connor24-Oct-13 5:45
Ivor O'Connor24-Oct-13 5:45 
GeneralMy vote of 1 Pin
Taha Akhtar22-Oct-13 2:15
professionalTaha Akhtar22-Oct-13 2:15 
GeneralRe: My vote of 1 Pin
Ted Goulden28-Oct-13 8:30
Ted Goulden28-Oct-13 8:30 
GeneralRe: My vote of 1 Pin
Dipesh Wadhwa29-Oct-13 0:08
Dipesh Wadhwa29-Oct-13 0:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.