1

I am having a problem while using the HTML Agility Pack. I have an html file. All I do is load that file using an HtmlDocument instance, and replace the urls of images in the document. Given below is the code used:

HtmlDocument htmlDoc = new HtmlDocument();
            htmlDoc.OptionFixNestedTags = true;

            htmlDoc.Load(filePath);
            HtmlNodeCollection images = htmlDoc.DocumentNode.SelectNodes("//img");
            string source;
            string imageName;
            string newSource;
            if (null != images && 0 < images.Count)
            {
                foreach (HtmlNode image in images)
                {
                    source = image.Attributes["src"].Value;
                    imageName = Path.GetFileName(source);                        
                    newSource = imageUris[imageUris.IndexOf(imageName)];
                    if (null != newSource)
                    {
                        image.Attributes["src"].Value = newSource;
                    }
                }
            }
            htmlDoc.Save(filePath);

The problem is that the Html document contains an empty check box and a check box with a 'x' created using the wingdigns font. After saving the file, the check box with 'x' in it gets changed to some weird characters like a left-pointing arrow, followed by 1 in a circle, followed by a clock and a number of A with ~ on top of it. Similar thing happens with the empty check box.

Can someone please suggest some solution to preserve the check boxes?

1
  • Sounds like an encoding issue, what encoding is the file path? (UTF-8, Unicode, ASCII, etc) Aug 8, 2012 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.