I am trying to read plain text from a MultiLineTextField in a List. This is how my code looks so far:
//Get connection
ClientContext context = new ClientContext("URL");
Web site = context.Web;
context.Load(site);
context.ExecuteQuery();
//Get list collection
ListCollection lists = context.Web.Lists;
context.Load(lists);
context.ExecuteQuery();
//Get specific list
List menu = lists.GetByTitle("menu");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXML = "<View/>";
ListItemCollection dishes = menu.GetItems(camlQuery);
context.Load(menu);
context.Load(dishes);
context.ExecuteQuery();
//Iterate through all dishes
foreach(ListItem dish in dishes)
{
Console.WriteLine("Dish: {0}:", dish.FieldValues["Name"]);
Console.WriteLine("Price: {0}:", dish.FieldValues["Price"]);
//Here I get my problem
Console.WriteLine("Ingredients: {0}:", dish.FieldValues["Ingredients"]);
}
In the last line where I try to read the ingredients, I am reading from a MultiLineTextField which is set to RichText. It is also supposed to stay in RichText format, as hyperlinks are supposed to be added there. The problem is that the output not only contains div-tags but also some weird question marks I never added to the field. I am trying to solve this issue for a couple of days now but it seems that there are only two possible solutions.
- Set the field from RichText to PlainText, which is not an option in my case.
- Use Regex to remove the div-tags. Please do not suggest this option. Mainly because I do not consider this to be a clean solution for this issue. Plus, I tried it and it removes the tags but those weird question marks stay.
There seems to be a third option I found here. It is also mentioned in this question and it seems to work. But I can not get it to work for me. This is how it looks:
string myString = item.FieldMultiLineText[Field_Name]
So I wonder what is item
supposed to be here? I suppose it is not a ListItem
because in my case it does not offer a FieldMultiLineText
-property.
A short, informative code snippet would be great if you decide to help me with this issue.
Thanks in advance.