Introduction:
This article quickly goes over the programmatic handling of multi-line text columns. Multi-line columns are useful within SharePoint because they allow a large quantity of descriptive texted to be stored as metadata, while only using a single column. They can hold specifications, use conditions, history, notes or even pictures. However, the more extensive the functionality of the text column, the more difficult the field will become to handle. When creating a multi-line text column, you will find the following options:

The “Number of lines for editing:” number box indicates how many lines a SharePoint user will have to type text into this field, when editing the corresponding item. It does not limit how many lines of text this field can hold. If this field contains more than 6 lines of text, a scroll bar will be provided to the SharePoint user to look through the entire text.
In order to demonstrate the programmatic implication of the three radio buttons, the rest of this article will go as follows:
1) First, I will briefly explain the benefits of each option.
2) Then, I will show you what they look like when being populated and when they are side by side.
3) Afterwards, I’ll show you the two ways to capture the field’s data, and the code surrounding the data acquisition. I will also show you what the acquired data looks like for each radio option-data acquisition combination.
4) Finally, I will show you how to populate these fields.
The Benefits:
Plain text is pretty simple. While it will not allow simple formatting, such as underlining or bolding, it will however predictably provide Environment.Newline comparisons. This can be quite helpful if rich formatting is not necessary.
Rich text and enhanced rich text are very similar, while obviously the enhanced rich text has more options, such as posting pictures. I have never found a reason to not use Enhanced rich text if I’m going to use Rich text anyway. The only reason you might want to use rich text instead of enhanced rich text is if you want to forbid the posting of pictures. One obvious reason for this is, the height of each row in SharePoint will become quite large for each list item.
How it Looks:
Here is how the 3 fields look when the user is filling them out. Notice how the user only has 6 lines to view text, but there is also a scroll bar so the user can continue to input even more lines of text.

Furthermore, here is how the fields look when side by side in a SharePoint List.



Programmatic Handling:
Finally, let’s talk about how to handle them in C#. In my experience, I’ve found multi-line text columns to be more of a nuisance than even look up columns. Capturing their information is rather counter intuitive and difficult to remember. This is primarily why I wrote this article. To capture the text within a multi-line text column, you must first declare a SPFieldMultiLineText object.
SPFieldMultiLineText plainText = item.Fields.GetField("PlainText") as SPFieldMultiLineText;
Notice we cannot simply use item[“PlainText”].
To display this text, we can use one of two methods:
1) plainText.GetFieldValueAsText(object value)
2) plainText.GetFieldValueAsHTML(object value)
To make this code even more counter-intuitive, the parameters for both of these methods are a single object with no description. What actually goes into these parameters is item["PlainText"]. That is, the splistitem from which this column value is coming from, and the column itself’s name.
To show you what these methods return, here is the code that I used in a console application. It is wrapped in a using statement with a SPWeb.
//declare necessary variables.
SPList list = web.Lists["Multi-line Text"];
SPListItem item = list.Items[0];
int count;
//get info from multi-line column
SPFieldMultiLineText mlt = item.Fields.GetField(FIELD_NAME) as SPFieldMultiLineText;
string asText = mlt.GetFieldValueAsText(item[FIELD_NAME]);
string asHtml = mlt.GetFieldValueAsHtml(item[FIELD_NAME]);
//display field value as text
Console.WriteLine("Plain text multi-line column: get field as text: " +
Environment.NewLine + Environment.NewLine + asText);
count = 0;
for (int i = 0; i < asText.Length - 1; i++)
{
if (asText.Substring(i, 2) == Environment.NewLine)
count++;
}
Console.WriteLine("Total Environment.NewLine registered: " + count);
Console.WriteLine(Environment.NewLine + "----------------------");
//display field value as html
Console.WriteLine("Plain text multi-line column: get field as html: " +
Environment.NewLine + Environment.NewLine + asHtml);
count = 0;
for (int i = 0; i < asHtml.Length - 1; i++)
{
if (asHtml.Substring(i, 2) == Environment.NewLine)
count++;
}
Console.WriteLine("Total Environment.NewLine registered: " + count);
Console.ReadLine();
Results:
Here are the results for FIELD_NAME = "PlainText":

Here are the results for FIELD_NAME = "RichText":

Finally, here are the results for FIELD_NAME = "EnhancedRichText":

Now you might say, well the NewLine counts are accurate, so what gives? Why are rich texts more difficult to programmatically handle? Because, while users might make ample use of pictures, lists and formatting, capturing such details will be impossible with .GetFieldValueAsText, and .GetFieldValueAsHtml will be riddled with unpredictable tags.
Populating Multi-line Text Fields:
Lastly, how do we populate Multi-Line Text Fields? Well, this is actually a lot simpler. Simply use a code such as:
item["MultiLine"] = "<u>Line One</u>." + Environment.NewLine +
"<i>Line Two.</i>" + "<br>" + "<b>Line Three.</b>";
item.Update();
In this case, “MultiLine” is a rich multi-line column. The results are as follows:

Notice, the Environment.NewLine did not register.
If “MultiLine” is a plain text multi-line column then we instead get the following result from the same code:

Notice that the html tags are now meaningless. Therefore, knowing if the column is rich text of plain text is quite important. To find out during runtime, simply use this:
SPFieldMultiLineText mlt = …
bool isRichText = mlt.RichText;
By: Arjun Chakraborty