0
votes

I have an issue with CSOM and content type, I used CSOM to read some value in a sharepoint list, it works well until I try to used content type If I create a new content type with my fields, it's worked but if I add my field in an existing content type. It doesn't work and that's return me the following error:

Error: Object reference not set to an instance of an object 

Here a piece of code from where my error is comming:

 List list = web.Lists.GetByTitle("myList");
    CamlQuery query = CamlQuery.CreateAllItemsQuery();
    ListItemCollection items = list.GetItems(query);
    l_objCtx.Load(items, its => its.Include(item => item[ColumnName], item => item.Id));
    l_objCtx.ExecuteQuery();

    foreach (var item in items)
    {
          m_strGetprimary = item.Id.ToString();
          return true;
    }

I've done a lot of researches but I found nothing related to this issue

Any idea of what I'm doing wrong?

Thank you for your help

1

1 Answers

0
votes

After adding SharePoint field to existing content type please check field name that you have just added. Sometimes it can be different and then your variable ColumnName might have wrong text value.

How to check it:

  1. Go to site settings > Site content types > Your content type.
  2. Select/click your field and in URL you will have param Field={field name}.