Sets the various options for removing dangerous Html content.
An enumeration for removing parts of Html. By default, its value is set to Remove the following parts of Html:
HtmlRemovalOptions.AppletTag
HtmlRemovalOptions.EmbedTag
HtmlRemovalOptions.NoScriptTag
HtmlRemovalOptions.ObjectTag
HtmlRemovalOptions.ParamTag
HtmlRemovalOptions.Scripts
HtmlRemovalOptions.ViewState
Note: When calling HtmlUtility.Render(), scripts will always be removed, even if HtmlRemovalOptions = HtmlRemovalOptions.None.
[C#]
HtmlUtility utility = new HtmlUtility();
string url = "http://www.microsoft.com";
//replace all removed html with an empty string. By default, a comment is left in place where text was removed.
utility.HtmlRemovalOptions = utility.HtmlRemovalOptions | HtmlRemovalOptions.ReplaceWithEmptyString;
//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;
//resolve Hrefs so they are absolute
utility.ResolveHrefs = 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 To, From, Server, etc... values from the web.config
email.LoadFromConfig();
email.Subject = "Html Utility Test";
email.Send();
[VB.NET]
Dim utility As New HtmlUtility()
Dim url As String = "http://www.microsoft.com"
'replace all removed html with an empty string. By default, a comment is left in place where text was removed.
utility.HtmlRemovalOptions = utility.HtmlRemovalOptions Or HtmlRemovalOptions.ReplaceWithEmptyString
'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
'resolve Hrefs so they are absolute
utility.ResolveHrefs = 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 To, From, Server, etc... values from the web.config
email.LoadFromConfig()
email.Subject = "Html Utility Test"
email.Send()