views:

195

answers:

4

I say that How can i get HTML code of a page in c# asp.net

Ex:- http://Google.com How i can get his html code by asp.net c#

+1  A: 

MSDN example of HttpWebrequest.GetResponse has working code.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx

No Refunds No Returns
Thanks i already checked it
+12  A: 

The WebClient class will do what you want:

string address = "http://stackoverflow.com/";   

using (WebClient wc = new WebClient())
{
    string content = wc.DownloadString(address);
}

As mentioned in the comments, you might prefer to use the async version of DownloadString to avoid blocking:

string address = "http://stackoverflow.com/";

using (WebClient wc = new WebClient())
{
    wc.DownloadStringCompleted +=
        new DownloadStringCompletedEventHandler(DownloadCompleted);
    wc.DownloadStringAsync(new Uri(address));
}

// ...

void DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if ((e.Error == null) && !e.Cancelled)
    {
        string content = e.Result;
    }
}
LukeH
VERY VERY THANKS Luke for Help Me
This will work BUt your page will block until the subsequent download completes. Consider using the async methods.
No Refunds No Returns
don't worry about it just say answer @ http://stackoverflow.com/questions/1821348/how-do-regex-find-out-all-hyperlink-in-html-page
A: 

If the question is "How to get the code-behind file of a web page", the answer is "No can do"

Vedran
@anirudha Gupta Warning: Please note the "IF" at the beginning of Vedran's answer. Your question was not very clear so be careful with your wording in the future or your questions may get downvoted.
Dave Swersky
pardon for it but i not know english well so are you edit my question
A: 

If you are planning to do a lot of web requests to access rest services, be careful with the HttpWebRequest object. It takes a while to be reclaimed and if you have enough traffic (just a few calls a minute), you can start to get strange behavior.

if you are loading other pages dynamically, I'd recommend doing it in javascript.

Derek G
i can't know well your answer's meaning well i use it for get html code not for any other matter