Class HtmlUtils
HtmlUtils is a Utility class that provides Html Utility methods.
Inheritance
Namespace: DotNetNuke.Common.Utilities
Assembly: DotNetNuke.dll
Syntax
public class HtmlUtils : object
Methods
| Improve this Doc View SourceAbsoluteToRelativeUrls(String, IEnumerable<String>)
Searches the provided html for absolute hrefs that match the provided aliases and converts them to relative urls.
Declaration
public static string AbsoluteToRelativeUrls(string html, IEnumerable<string> aliases)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The input html. |
IEnumerable<System.String> | aliases | a list of aliases that should be made into relative urls. |
Returns
Type | Description |
---|---|
System.String | html string. |
Clean(String, Boolean)
Clean removes any HTML Tags, Entities (and optionally any punctuation) from a string.
Declaration
public static string Clean(string html, bool removePunctuation)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML to clean. |
System.Boolean | removePunctuation | A flag indicating whether to remove punctuation. |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
Remarks
Encoded Tags are getting decoded, as they are part of the content!.
CleanWithTagInfo(String, String, Boolean)
CleanWithTagInfo removes unspecified HTML Tags, Entities (and optionally any punctuation) from a string.
Declaration
public static string CleanWithTagInfo(string html, string tagsFilter, bool removePunctuation)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | |
System.String | tagsFilter | |
System.Boolean | removePunctuation |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
ContainsEntity(String)
Checks whether the string contains any HTML Entity or not.
Declaration
public static bool ContainsEntity(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
Returns
Type | Description |
---|---|
System.Boolean | True if the string contains any entity. |
ConvertToHtml(String)
Formats strText
as HTML by replacing line feeds by <br />
.
Declaration
public static string ConvertToHtml(string strText)
Parameters
Type | Name | Description |
---|---|---|
System.String | strText | Text to format. |
Returns
Type | Description |
---|---|
System.String | The formatted HTML. |
ConvertToText(String)
Formats HTML as text by removing <br />
tags and replacing by linefeeds.
Declaration
public static string ConvertToText(string strHtml)
Parameters
Type | Name | Description |
---|---|---|
System.String | strHtml | HTML to format. |
Returns
Type | Description |
---|---|
System.String | The formatted text. |
FormatEmail(String, Boolean)
Formats an Email address.
Declaration
public static string FormatEmail(string email, bool cloak)
Parameters
Type | Name | Description |
---|---|---|
System.String | The email address to format. |
|
System.Boolean | cloak | A flag that indicates whether the text should be cloaked. |
Returns
Type | Description |
---|---|
System.String | The formatted email address. |
FormatEmail(String)
Formats an Email address as a cloaked html link.
Declaration
public static string FormatEmail(string email)
Parameters
Type | Name | Description |
---|---|---|
System.String | The email address to format. |
Returns
Type | Description |
---|---|
System.String | The email address as a cloaked html link. |
FormatText(String, Boolean)
FormatText replaces <br />
tags by LineFeed characters.
Declaration
public static string FormatText(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Whether retain Space. |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
FormatWebsite(Object)
Format a domain name including link.
Declaration
public static string FormatWebsite(object website)
Parameters
Type | Name | Description |
---|---|---|
System.Object | website | The domain name to format. |
Returns
Type | Description |
---|---|
System.String | The formatted domain name. |
IsHtml(String)
Determines whether or not the passed in string contains any HTML tags.
Declaration
public static bool IsHtml(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | Text to be inspected. |
Returns
Type | Description |
---|---|
System.Boolean | True for HTML and False for plain text. |
IsUrlEncoded(String)
Checks whether the string contains any URL encoded entity or not.
Declaration
public static bool IsUrlEncoded(string text)
Parameters
Type | Name | Description |
---|---|---|
System.String | text | The string check. |
Returns
Type | Description |
---|---|
System.Boolean | True if the string contains any URL encoded entity. |
RemoveInlineStyle(String)
Removes Inline CSS Styles.
Declaration
public static string RemoveInlineStyle(string html)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
Shorten(String, Int32, String)
Shorten returns the first length
characters of a string.
Declaration
public static string Shorten(string txt, int length, string suffix)
Parameters
Type | Name | Description |
---|---|---|
System.String | txt | The text to reduce. |
System.Int32 | length | The max number of characters to return. |
System.String | suffix | An optional suffix to append to the shortened string. |
Returns
Type | Description |
---|---|
System.String | The shortened string. |
StripEntities(String, Boolean)
StripEntities removes the HTML Entities from the content.
Declaration
public static string StripEntities(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Indicates whether to replace the Entity by a space (true) or nothing (false). |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
StripNonWord(String, Boolean)
StripNonWord removes any Non-Word Character from the content.
Declaration
public static string StripNonWord(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Indicates whether to replace the Non-Word Character by a space (true) or nothing (false). |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
StripPunctuation(String, Boolean)
StripPunctuation removes the Punctuation from the content.
Declaration
public static string StripPunctuation(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Indicates whether to replace the Punctuation by a space (true) or nothing (false). |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
StripTags(String, Boolean)
StripTags removes the HTML Tags from the content.
Declaration
public static string StripTags(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Indicates whether to replace the Tag by a space (true) or nothing (false). |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
StripUnspecifiedTags(String, String, Boolean)
StripUnspecifiedTags removes the HTML tags from the content -- leaving behind the info for the specified HTML tags.
Declaration
public static string StripUnspecifiedTags(string html, string specifiedTags, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | |
System.String | specifiedTags | |
System.Boolean | retainSpace |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
StripWhiteSpace(String, Boolean)
StripWhiteSpace removes the WhiteSpace from the content.
Declaration
public static string StripWhiteSpace(string html, bool retainSpace)
Parameters
Type | Name | Description |
---|---|---|
System.String | html | The HTML content to clean up. |
System.Boolean | retainSpace | Indicates whether to replace the WhiteSpace by a space (true) or nothing (false). |
Returns
Type | Description |
---|---|
System.String | The cleaned up string. |
WriteError(HttpResponse, String, String)
WriteError outputs an Error Message during Install/Upgrade etc.
Declaration
public static void WriteError(HttpResponse response, string file, string message)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | The ASP.Net Response object. |
System.String | file | The filename where the Error Occurred. |
System.String | message | The error message. |
WriteFeedback(HttpResponse, Int32, String, Boolean)
WriteFeedback outputs a Feedback Line during Install/Upgrade etc.
Declaration
public static void WriteFeedback(HttpResponse response, int indent, string message, bool showtime)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | The ASP.Net Response object. |
System.Int32 | indent | The indent for this feedback message. |
System.String | message | The feedback message. |
System.Boolean | showtime | Show the timespan before the message. |
WriteFeedback(HttpResponse, Int32, String)
WriteFeedback outputs a Feedback Line during Install/Upgrade etc.
Declaration
public static void WriteFeedback(HttpResponse response, int indent, string message)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | The ASP.Net Response object. |
System.Int32 | indent | The indent for this feedback message. |
System.String | message | The feedback message. |
WriteFooter(HttpResponse)
WriteFooter outputs the Footer during Install/Upgrade etc.
Declaration
public static void WriteFooter(HttpResponse response)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | The ASP.Net Response object. |
WriteHeader(HttpResponse, String)
WriteHeader outputs the Header during Install/Upgrade etc.
Declaration
public static void WriteHeader(HttpResponse response, string mode)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | The ASP.Net Response object. |
System.String | mode | The mode Install/Upgrade etc. |
WriteKeepAlive()
This method adds an empty char to the response stream to avoid closing http connection on long running tasks.
Declaration
public static void WriteKeepAlive()
WriteScriptSuccessError(HttpResponse, Boolean, String)
HtmlUtils is a Utility class that provides Html Utility methods.
Declaration
public static void WriteScriptSuccessError(HttpResponse response, bool bSuccess, string strLogFile)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | |
System.Boolean | bSuccess | |
System.String | strLogFile |
WriteSuccessError(HttpResponse, Boolean)
HtmlUtils is a Utility class that provides Html Utility methods.
Declaration
public static void WriteSuccessError(HttpResponse response, bool bSuccess)
Parameters
Type | Name | Description |
---|---|---|
HttpResponse | response | |
System.Boolean | bSuccess |