Pages

30 November 2011

View source trang web bằng C#

Tạo phương thức ReadHTMLCode(string URL)


private string ReadHTMLCode(string URL)
{
try
{
WebClient webClient = new WebClient();
byte[] reqHTML;
reqHTML = webClient.DownloadData(URL);
UTF8Encoding objUTF8 = new UTF8Encoding();
return objUTF8.GetString(reqHTML);
}
catch (Exception Ex)
{
MessageBox.Show(Ex.Message,"Unable to open file from URL");
}
return "error";
}