0

how to i get CSOM code retrieve multi line text from sharePoint online?

i was able to get other fields relatively easily

                Web web = ctx.Web;
                List list = web.Lists.GetById(new Guid("fe15d182-4e65-48a9-a613-6dcfae756c69"));
                var q = new CamlQuery() { ViewXml = "<View><Query><Where><Eq><FieldRef Name='Manager' /><Value Type='User'>TOM</Value></Eq></Where></Query></View>" };
                var r = list.GetItems(q);
                ctx.Load(r);


                string result = string.Empty;
                foreach (SPclient.ListItem itm in r)
                {
                    FieldUserValue name = itm.FieldValues["Manager"] as FieldUserValue;
                    string person = name.LookupValue;
                    //Console.WriteLine(itm.Id + "     " + itm["Manager"].ToString() + "     " + person);

                    MessageBox.Show(itm.Id + "     " + itm["Title"].ToString() + "     " + multitextValue + "    " + person);
                }

3 Answers 3

0

You need to load FieldValuesAsText explicitly.

Try it as below:

Web web = ctx.Web;
List list = web.Lists.GetById(new Guid("fe15d182-4e65-48a9-a613-6dcfae756c69"));
var q = new CamlQuery() { ViewXml = "<View><Query><Where><Eq><FieldRef Name='Manager' /><Value Type='User'>TOM</Value></Eq></Where></Query></View>" };
var r = list.GetItems(q);
ctx.Load(r,items=>items.Include(item=>item.FieldValuesAsText));    
ctx.ExecuteQuery();

foreach (SPclient.ListItem itm in r)
{
    FieldUserValue name = itm.FieldValues["Manager"] as FieldUserValue;
    string person = name.LookupValue;

    string richTextField = Convert.ToString(itm.FieldValuesAsText[FIELD_NAME]); //internal name of field

    //Console.WriteLine(itm.Id + "     " + itm["Manager"].ToString() + "     " + person);

    MessageBox.Show(itm.Id + "     " + itm["Title"].ToString() + "     " + multitextValue + "    " + person);
}
4
  • Thanks Gautam, I got an error on the line string richTextField = Convert.ToString(itm.FieldValuesAsText["SubordinateEmails"]); Error {"The property or field has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested."}"
    – Rinu
    Feb 27, 2017 at 7:57
  • Field name SubordinateEmails is correct.
    – Rinu
    Feb 27, 2017 at 7:58
  • Can you check edited code ? have added ctx.ExecuteQuery method Feb 27, 2017 at 8:17
  • the above code does not enter the for loop
    – Rinu
    Feb 27, 2017 at 8:34
0

Try the below code

var listItem = list.GetItemById(itemId);
var FieldValues = listItem.FieldValuesAsText;
clientContext.Load(FieldValues);
clientContext.ExecuteQuery();
string multitextfield = FieldValues["MultiLine FieldName"];

Your Answer

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

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