Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
    
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 Dec 20 '12 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 Dec 20 '12 at 16:16
add comment

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
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 Dec 19 '12 at 23:05
    
I updated my answer. –  Mike Dec 20 '12 at 14:30
    
That looks like it will work I'll give it a try, thanks. You also updated your gravatar! –  cbrad Dec 20 '12 at 16:13
    
Why yes, yes I did. Let me know if that works for you! –  Mike Dec 20 '12 at 18:42
    
Works perfectly, accepted as answer. Thanks! –  cbrad Dec 20 '12 at 19:08
add comment

Your Answer

 
discard

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.