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

Advertisements

2 thoughts on “Remove HTML Tags in SharePoint 2010

  1. Ahmed Elsheemy

    Thanks so much that’s really what i need ,, but where i can put this name space ? in the master page or where

    Thanks again

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s