aspNetEmail

HtmlUtility Class

An engine class for manipulating Html content..

For a list of all members of this type, see HtmlUtility Members.

System.Object
   HtmlUtility

public class HtmlUtility

Remarks

This class will allow the developer to create properly formatted html content with embedded images.

The Html content can be in the form of a string or can be loaded from an http:// or file:// location using the Load( string url) method.

Overview
The property RawHtmlContent is a Html string that will be parsed by the HtmlUtility class. The HtmlUtility class will extract all image locations and, based upon the UrlContentBase property, attempt to locate all images and download them.

If the developer wishes to extract the Html content from a http:// or a file:/// location, the LoadHtml( string url ) method can be used. When this method is used, the RawHtmlContent value is populated, along with the UrlContentBase.

Once the RawHtmlContent property has been populated, the Render() method can be called. The Render() method will extract all image information and download the images to a byte array. Using this byte array, the HtmlUtility class will populate the public EmbeddedImages array property. This array can then be used by the EmailMessage object to load embedded email objects.

Note:
To prevent unauthorized use to the file system, the AllowFileScheme property must be set to true to load Html content from a file:/// location.

Example

[C#]
            HtmlUtility utility = new HtmlUtility();
            string url = "http://www.microsoft.com";
             
            //convert linked css sheets to inline <style> content
            utility.CssOption = CssOption.EmbedLinkedSheets;
             
            utility.LoadUrl( url );
             
            //set the UrlContent base
            utility.SetUrlContentBase = true;
             
            //set the basetag in the html
            utility.SetHtmlBaseTag = true;
             
            //embed the images
            utility.EmbedImageOption  = EmbedImageOption.ContentLocation;
             
            //render the Html so it is properly formatted for email
            utility.Render();
             
            //create an EmailMessage with appropriate text and html parts
            EmailMessage email = utility.ToEmailMessage();
             
            //load values from the web.config
            email.LoadFromConfig();
             
            email.Subject = "Html Utility Test";
             
            email.Send();
                
[Visual Basic]
            Dim utility As New HtmlUtility()
            Dim url As String = "http://www.microsoft.com"
             
            'convert linked css sheets to inline <style> content
            utility.CssOption = CssOption.EmbedLinkedSheets
             
            utility.LoadUrl(url)
             
            'set the UrlContent base
            utility.SetUrlContentBase = True
             
            'set the basetag in the html
            utility.SetHtmlBaseTag = True
             
            'embed the images
            utility.EmbedImageOption = EmbedImageOption.ContentLocation
             
            'render the Html so it is properly formatted for email
            utility.Render()
             
            'create an EmailMessage with appropriate text and html parts
            Dim email As EmailMessage = utility.ToEmailMessage()
             
            'load values from the web.config
            email.LoadFromConfig()
             
            email.Subject = "Html Utility Test"
             
            email.Send()
                

Requirements

Namespace: aspNetEmail

Assembly: aspNetEmail (in aspNetEmail.dll)

See Also

HtmlUtility Members | aspNetEmail Namespace