Sunday, 25 October 2015

Programmatically check if a field is already existed in a SharePoint list or not using CSOM


In the method below, it is checked that if a particular field is already created/existed in a SharePoint 
list  or not. The return type of the list is bool. It returns true if the field is existed otherwise returns false.


 public static bool ContainsField(List list, string fieldName)
        {
            try
            {
                var ctx = list.Context;
                var result = ctx.LoadQuery(list.Fields.Where(f => f.InternalName == fieldName));

                ctx.ExecuteQuery();

                return result.Any();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }


Happy SharePointing.....................:)

No comments:

Post a Comment