C# - Get webpage source code

By , 8/23/2012
(1 ratings)
This function can be used to Get webpage source code

Just call this function like below

Literal1.InnerHTML=GetHtmlWebpage(string url)

YOU HAVE USE ANY CONTROL WHICH SUPPORTS TEXT RENDERING
 public string GetHtmlWebpage(string url)
        {           
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(txtGetOnlineWebpage.Text);
                myRequest.Method = "GET";
                WebResponse myResponse = myRequest.GetResponse();
                StreamReader sr = new StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
                string result = sr.ReadToEnd();
                sr.Close();
                myResponse.Close();
               return result;  
        }

Comments

 

Log in, to comment!