0

My problem is that i want to change the src value of some in the html of an email am getting. All this is already done, i used EWS api to establish connection and am using html agility pack to do the parsing. Anyone knows how to get the html with the changes i made to the src values in the images?

    public static string parsearHtml(string body,Item item, ArrayList contentIDS, ArrayList urls)
    {
        string SRC = "";
        int indice = 0;
        string retorno = "";
        //Console.WriteLine(body);

        HtmlDocument email = new HtmlDocument();
        email.LoadHtml(body);

        foreach (HtmlNode img in email.DocumentNode.SelectNodes("//img"))
        {
            SRC = img.GetAttributeValue("src", null);
            for (int i = 0; i < contentIDS.Count; i++)
            {
                if (SRC.Equals(contentIDS[i].ToString()))
                {
                    indice = i;
                    break;
                }
            }

            img.SetAttributeValue("src", urls[indice].ToString());
            Console.WriteLine(img.GetAttributeValue("src", null));//in here i get the the attribute and its change so the changing of src values is working
            //i tried email.save(retorno) but got error for empty path
            //so i tried email.save(body) but got error for illegar characters in path
        }

        return retorno;

   }
Pauli Østerø
  • 6,878
  • 2
  • 31
  • 48
rdk1992
  • 406
  • 1
  • 5
  • 20

1 Answers1

0

You can get whole html string with

email.DocumentNode.OuterHtml

Similar question answered at HTML Agility Pack HtmlDocument Show All Html?

Community
  • 1
  • 1
arunes
  • 3,464
  • 2
  • 21
  • 31
  • thx but work it around with memory stream anyways thanks for ur post. Btw have any ideas how to get external images in the html. Right know i only made the workaround with attachments. Have any idea how to get the reference image and convert it to an array of bytes or a image object in c#? – rdk1992 Feb 22 '12 at 15:01
  • am using htmlagilitypack, and i know how to get the src value of the image, but how do i get and store that physical image.dont want to store it in disk. Just like the attachments that were store in array of bytes. – rdk1992 Feb 22 '12 at 15:02
  • For downloading images to array of bytes, you can use WebClient class. There is a simple example at http://geekswithblogs.net/whiletrue/archive/2010/03/11/c-image-download.aspx – arunes Feb 22 '12 at 19:10