• Share
    • Twitter
    • LinkedIn
    • Facebook
    • Email
  • Feedback
  • Improve this Doc

Class HtmlUtils

HtmlUtils is a Utility class that provides Html Utility methods.

Inheritance
System.Object
HtmlUtils
Namespace: DotNetNuke.Common.Utilities
Assembly: DotNetNuke.dll
Syntax
public class HtmlUtils : object

Methods

| Improve this Doc View Source

AbsoluteToRelativeUrls(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.

| Improve this Doc View Source

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!.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

FormatEmail(String, Boolean)

Formats an Email address.

Declaration
public static string FormatEmail(string email, bool cloak)
Parameters
Type Name Description
System.String email

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.

| Improve this Doc View Source

FormatEmail(String)

Formats an Email address as a cloaked html link.

Declaration
public static string FormatEmail(string email)
Parameters
Type Name Description
System.String email

The email address to format.

Returns
Type Description
System.String

The email address as a cloaked html link.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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.

| Improve this Doc View Source

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()
| Improve this Doc View Source

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
| Improve this Doc View Source

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

Extension Methods

JsonExtensionsWeb.ToJson(Object)
  • View Source
Back to top by the community, for the community... #DNNCMS