2

I have a list field of the type "Multiple Lines of Text". When I retrieve it in my code-behind using item["field"].ToString(), it prints out the text, but without line-breaks. How can I add line breaks to the text?

What I have:

<p>Text text text.
Text text text.
Text Text Text.</p>

What I want:

<p>Text text text.<br/>
Text text text.<br/>
Text Text Text.</p>
1

try using the below way:

1) While creating a multi-line list column, create as a enhanced rich text as below: enter image description here

2) While retrieving text using the below c# code

Using Span:

SPFieldMultiLineText mlt = list.Fields.GetField("MultiLineField") as SPFieldMultiLineText;
spanID.InnerHtml = mlt.GetFieldValueAsHtml(list["MultiLineField"] as string);

Using SharePoint TextBox:

Control

<SharePoint:InputFormTextBox ID="txtID" runat="server" TextMode="MultiLine" RichTextMode="FullHtml" RichText="true" />

c# code:

txtID.Text = mlt.GetFieldValueAsHtml(list["MultiLineField"] as string);
0

The best solution I have found to retrieve HTML-formated text with line-brakes is replacement. SharePoint classes and methods didn't help.

Convert.ToString(item["field"]).Replace("\r\n", "<br>");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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