Sunday 26 June 2016

download html content of a page by its URL in asp.net c#.

public void GetPageHtmlBy Url()
{
// using System.Net;
WebClient webClient = new WebClient();
// Get Web Page URL that content you want to send in email.
string strUrl = “abc.aspx?id=100”;
byte[] reqHTML;
reqHTML = webClient.DownloadData(strUrl);
UTF8Encoding objUTF8 = new UTF8Encoding();
string PgStr = objUTF8.GetString(reqHTML);
System.Text.RegularExpressions.Regex regxmaster1 = new System.Text.RegularExpressions.Regex(“(<input type=\”submit\”)(.*?)(/>)”, System.Text.RegularExpressions.RegexOptions.Singleline);
System.Text.RegularExpressions.Match matchmaster1 = regxmaster1.Match(PgStr);
string inputype1 = matchmaster1.Groups[0].Value.Trim();
if (inputype1.Trim() != “”)
{
PgStr = PgStr.Replace(inputype1, “”);
}
// replace any value
string imgUrl=””;
PgStr = PgStr.Replace(” id=\”img1\””, ” src=\”” + imgUrl + “\”  id=\”img1\””);
// remove any text or control conditionaly
if (Request.QueryString[“flag”].ToString() == “M”)
{
PgStr = PgStr.Remove(PgStr.IndexOf(“Full Details”), 9);
}
// here you  can  use content from  other page as mail body or  display other place.
}

No comments:

Post a Comment