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#
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#
MSDN example of HttpWebrequest.GetResponse has working code.
http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.getresponse.aspx
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;
}
}
If the question is "How to get the code-behind file of a web page", the answer is "No can do"
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.