Wednesday, October 16, 2013

SharePoint 2013/2016: Adding a Rich Text Column to a List Using CSOM

When you add a rich text column to a list from the SharePoint UI, you select Multiple lines of text as the type of information:

Towards the bottom, you have two type of text options, Plain text or Enhanced rich text:

After you create the column and go back in to edit the properties, you now get a third "in-between" Rich text option:

I needed to add a rich text column programatically to a list using the client side object model (CSOM). I found general guidelines for adding a field to a list here on MSDN.

Based on that post, I followed suit and constructed my code:

Field styleField = list.Fields.AddFieldAsXml("<Field DisplayName='Style' Type='Note' />", true, AddFieldOptions.DefaultValue);
FieldMultiLineText fieldMultiLineText = context.CastTo<FieldMultiLineText>(styleField);
fieldMultiLineText.RichText = true;
fieldMultiLineText.AllowHyperlink = true;

I knew what the real type of Field the object was so I casted it to FieldMultiLineText. This allowed me to set the RichText property to true. However, upon generation, the settings of the column where just the regular Rich Text:

This was actually what I needed but I thought, how do you create one as Enhanced rich text? There is a RichTextMode property but it is not exposed in a FieldMultiLineText object. After trying several different things, I just decided to read the properties of a created Enhanced rich text column and use the SchemaXML to generate the new field:

Field rtfField = list.Fields.AddFieldAsXml("<Field DisplayName=\"Enhanced RTF\" Type=\"Note\" RestrictedMode=\"TRUE\" RichText=\"TRUE\" RichTextMode=\"FullHtml\" RowOrdinal=\"0\" Required=\"FALSE\" EnforceUniqueValues=\"FALSE\" Indexed=\"FALSE\" NumLines=\"6\" IsolateStyles=\"TRUE\" AppendOnly=\"FALSE\" />"
, true, AddFieldOptions.DefaultValue);


RestrictedMode=\"TRUE\" RichText=\"TRUE\" RichTextMode=\"FullHtml\"
I believe that these properties are the key to creating it properly. I did not perform any casts as it seemed that was working against me. Once I just used the Field object and the XML, all was good:


  1. Why does my multiple lines of text type not show the Enhanced rich text option in SharePoint 2013?

    1. Not sure. I would have to look.

    2. Not sure. I would have to look.

    3. This might be because you are trying to add that in a document library for which the option would not be Shown in the Sharepoint page and instead you would have to try to make the change using the SharePoint Designer.

    4. This would be because you are trying to add this in a document library for which you need to make the changes from the SharePoint Designer.

  2. Hi, I have a multiple lines of text column with rich text enabled. However when we edit the properties of the item in the library, the column can only be completed in plain text - there is no rich text editor. Can you help please? Tracey

    1. Did you try different browsers? IE vs. Chrome?

  3. It's a shame you don't have a donate button! I'd most certainly donate to this fantastic blog!

    I guess for now i'll settle for book-marking and adding your RSS
    feed to my Google account. I look forward to fresh updates and will talk about this site with my Facebook group.

    Chat soon!

  4. Thank you! very well explained! Is work to me!


Matched Content