Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

You can easily get the HTML of the page in a string variable. That html can be of a page such as or any other page. You only need to use the WebClient class which is in System.Net.

Here is the code which retrieves the HTML of the currently running page:

protected void Button1_Click(object sender, EventArgs e)
        WebClient myClient = 
new WebClient();
string myPageHTML = null;
byte[] requestHTML; 
// Gets the url of the page
string currentPageUrl = Request.Url.ToString();

        UTF8Encoding utf8 = 
new UTF8Encoding();
// by setting currentPageUrl to it will fetch the source (html) 
        // of the and put it in the myPageHTML variable. 

       // currentPageUrl = ""; 
requestHTML = myClient.DownloadData(currentPageUrl);

        myPageHTML = utf8.GetString(requestHTML); 

The good thing is that you can use the regular expressions on the HTML to extract the pieces that you want.


powered by IMHO


Posted on Monday, October 24, 2005 9:20 PM | Back to top

Comments on this post: Getting the HTML of the Page in a string variable

# re: Getting the HTML of the Page in a string variable
Requesting Gravatar...
Works nicely unless you have Forms Authentication and Session variables - got any ideas for that ?

Left by john f on Feb 20, 2008 5:25 AM

Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: