Question

I want to check to see if a field exists in my program, but If I use :

if (item[_strContainingFieldName] != null)
{
    item[_strContainingFieldName] = fieldValue;
}

I receive an error stating

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.

So I wanted to use List.Fields.ContainsField or properties.ListItem.Fields.ContainsField but forgot I can only use these in the server API.

Is there something similar which I can make use of right now? The tool will be a "throw away" application since we're making updates behind the scenes, so I'm not too worried about catching every possibility and logging everything.

Note: The language is C#

Was it helpful?

Solution

From the error i think you are using CSOM. If yes, then you have to load the properties before using it.

context.Load(item); 
context.ExecuteQuery();

To check if field exists use following:

if(item.FieldValues.ContainsKey("salesdate"))
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top