Remove HTML Tags in SharePoint 2010

Standard

Always I’ve  faced the same problem and solved it in the same why when I deal with text fields in SharePoint which is remove the Html tags for the returned text to display it as a plain text. Each time my best solution is googling for the regular expression to replace Html tags with empty string 😦

Unfortunately  I find a method in Microsoft.SharePoint namespace to do this and offer also sub string for the returned text which is:

SPHttpUtility.ConvertSimpleHtmlToText(HTMLText , maxLength);

To remove tags and sub string it to max length

or

SPHttpUtility.ConvertSimpleHtmlToText(HTMLText , -1);

To remove tags only