convert image to base64

perfectchourasia-9163
Posted by perfectchourasia-9163 under ASP.NET category on | Points: 40 | Views : 2480
protected void Page_Load(object sender, EventArgs e)
{
HtmlWeb htmlWeb = new HtmlWeb();
HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("http://www.fortunehotels.in/");
foreach (HtmlNode someNode in document.DocumentNode.SelectNodes("//img[@src]"))
{
if (someNode.Attributes.Contains("src"))
{
if (someNode.Attributes["src"].Value.EndsWith(".jpg"))
{
if (someNode.Attributes["src"].Value != "admin/UploadImage/summer-packages2010717138.jpg")
{
if (someNode.Attributes["src"].Value != "admin/UploadImage/101X108201243356.jpg")
{
WebClient wc = new WebClient();
byte[] data = wc.DownloadData(someNode.Attributes["src"].Value);
string base64ImageString = ConvertBytesToBase64(data);
someNode.Attributes["src"].Value = "data:image/jpg;base64," + base64ImageString;
myImage.Src = "data:image/jpg;base64,"+base64ImageString;
}
document.Save("C:/Users/sandeep_2/Desktop/fortune.htm");
}
}
}
}
}
public string ConvertBytesToBase64(byte[] imageBytes)
{
return Convert.ToBase64String(imageBytes);
}

Comments or Responses

Login to post response