SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

List consists from Title (Single line of text) and Content (Multiple lines of text - Enhanced rich text) columns.

I need to get snippet from Content column(~125 first symbols). I've found that text in Content column formatted and contains html tags. I want to know, how I can programmatically get plain text from rich text? I know that I can use Regex, but it's not nice solution.

Have an answer?

share|improve this question

Didn't test, but you can probably use SPFieldMultiLineText.GetFieldValueAsText Method :

SPListItem yourItem = ....; // obtain the SPListItem with any method
SPFieldMultiLineText field = (SPFieldMultiLineText)yourItem.Fields["Content"]; 

string text = field.GetFieldValueAsText (yourItem["Content"]);
share|improve this answer

If you dont want to use this

string content = Regex.Replace(textWithHTML, "<.*?>", string.Empty);

you can use this, this returns the SPListItem as normal text

private string getFieldAsText(SPListItem item, string fieldName, string captionName)
            return ReferenceEquals(item[fieldName], null) ? string.Empty :
share|improve this answer

This is probably what you need:

const string htmlRegex = "<.*?>";

static string StripHTML (string inputString)
   // Removes all the HTML tags and returns the string with the 125 first characters
   return Regex.Replace(inputString, htmlRegex, string.Empty).Remove(125);
share|improve this answer
is there a solution without further processing? I mean is there method extracting plain text from SPListItem? – Nurlan Jan 12 '12 at 10:39
@Nurlan Not that I am aware of, no. – Daniel Ziga Jan 12 '12 at 10:41
@Nurlan Yes, see the answers. While this might work, I prefer the other methods. – Kit Menke Jan 12 '12 at 15:58

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.