4

When accessing a multi line text field from a SharePoint item in a list, what is the text type returned?

Using C#:

item["Description"].ToString()

Is the above plaintext or html or...?

I want to format the text to be put in a HTML email ultimately, but all formatting of the string in the actual description is lost when doing so.

2
  • What option did you choose? Rich text or Enhanced rich text? Usually you get html formatted text all the time if you choose rich text for multi line text column
    – Diptarag
    Commented Dec 20, 2012 at 6:18
  • I believe enhanced rich text. There were some benefits to it in terms of the WYSIWYG editing. I forget what those were now.
    – cbrad
    Commented Dec 20, 2012 at 16:16

1 Answer 1

2

You may have to change the description column using Powershell to include HTML.

$Web = Get-SPWeb "yoururl.domain.com/particularweb"
$Field = $web.Fields | ?{$_.staticname -eq "MyCustomColumn"}
$Field.RichText = $True
$Field.RichTextMode = "FullHtml"
$Field.Update()

Source: http://social.technet.microsoft.com/Forums/nl-NL/sharepointadminprevious/thread/a6d1b087-4d06-4e8f-8f69-043e15b04819

EDIT: Try this:

SPFieldMultiLineText multilineField = item.Fields.GetField(COLUMN_NAME) as SPFieldMultiLineText;

 if (multilineField != null)
 {
 // Get the field value as HTML
 string text = multilineField.GetFieldValueAsHtml(item[COLUMN_NAME], item);
 }

Source: http://blog.myitechnology.com/2009/06/append-new-line-to-spfieldmultilinetext.html

4
  • Hmm, it looks like this just changes the text fields to rich text, which allows HTML etc. I do already have my fields set up as rich text with HTML enabled. I'm just wondering when you pull data from fields programmatically, how those strings are formatted.
    – cbrad
    Commented Dec 19, 2012 at 23:05
  • I updated my answer.
    – Mike
    Commented Dec 20, 2012 at 14:30
  • That looks like it will work I'll give it a try, thanks. You also updated your gravatar!
    – cbrad
    Commented Dec 20, 2012 at 16:13
  • Why yes, yes I did. Let me know if that works for you!
    – Mike
    Commented Dec 20, 2012 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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