0

I changed a type of a Enhanced Rich Text column to Plain Text field.

enter image description here

I am seeing similar to the following content in the text field now.

<div class="ExternalClass3227FAEFAC38465BADF8165D56926D99"><p>This is used the text 16&#58;50&#160;​</p></div>

I wrote C# program (with CSOM) to iterate through each list item and strip the html tags and set just the text. I used regex, to strip html tags as mentioned in this post. It does remove the html tags, but it doesnt remove the html characters within the text. I tried, FieldValueAsText and didnt work for me.

I would like to know what the correct way is to achieve this.

1
  • Is there any update ? Did you try the solution in the answer ?
    – Jerry
    Nov 13, 2020 at 1:03

1 Answer 1

0

You can create another Plain text type column, use the code snippet to get text value from Enhanced rich text column using CSOM then set the Plain Text column with the text value got:

        ClientContext oClientContext = new ClientContext("http://sp/sites/MyDev");


        List list = oClientContext.Web.Lists.GetByTitle("List5");
        ListItem item = list.GetItemById(1);

        oClientContext.Load(item,a=>a.FieldValuesAsText);
        oClientContext.ExecuteQuery();
        item["Test1"]=item.FieldValuesAsText["Test"];
        item.Update();
        oClientContext.ExecuteQuery();

enter image description here

2
  • I cannot create new columns. There are many applications integrated with this list. So the column has to be the same and I already changed the column type. Then in my c# application I cleaned the html by removing the tags using regex and used html decoding for the remaining text. But I wanted to know if there is a proper way of achieving that. Nov 13, 2020 at 6:25
  • If have changed column type to plain text and don't want a new column, then this is the correct way to remove html character by using regex, but there maybe other special character, so regex maybe changed based on the real situation.
    – Jerry
    Nov 13, 2020 at 6:32

Your Answer

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

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