0

I am getting the following error when I am trying to run the following block of code.

error

Severity Code Description Project File Line Error CS1929 'FieldCollection' does not contain a definition for 'Contains' and the best extension method overload 'ParallelEnumerable.Contains(ParallelQuery, string)' requires a receiver of type 'ParallelQuery' OneDriveRetrival C:\FTG\Projects\OneDriveRetrival\OneDriveRetrival\OneDriveOperations\OneDriveOps.cs 86

Code:

 string SharedWithFieldDefXml = "< Field ID = '{ef991a83-108d-4407-8ee5-ccc0c3d836b9}’ Type=’UserMulti’ DisplayName=’Shared With’ Mult=’TRUE’ Name=’SharedWithUsers’ StaticName=’SharedWithUsers’ Group=’_Hidden’ Sealed=’TRUE’ AllowDeletion=’FALSE’ ReadOnly=’TRUE’ ShowInDisplayForm=’FALSE’ ShowInEditForm=’FALSE’ ShowInListSettings=’FALSE’ Viewable=’FALSE’ SourceID='{ 86ea65fd - 7aea - 4dd1 - afdb - bbbce3c16daa}’ />";

            if (web.AvailableFields.Contains(SharedWithFieldDefXml) == false)
            {

                web.Fields.AddFieldAsXml(MyFieldDefXml);

            }

2 Answers 2

2

I think you are confusing the SPFieldCollection object (server side) with the FieldCollection object (client side).

SPFieldCollection does have a Contains method, but as the error you are receiving points out, FieldCollection does not.

Here are links to the MSDN documentation:

SPFieldCollection

FieldCollection

1
  • Thank for the info
    – EasyE
    Jan 11, 2016 at 17:24
0

What you are doing looks like server object model code and this is not csom code at all which will only be compatible with your online site.

this is how you can create a new column using csom.

string SharedWithFieldDefXml = "<Field ID ='{ef991a83-108d-4407-8ee5-ccc0c3d836b9}’ Type=’UserMulti’ DisplayName=’Shared With’ Mult=’TRUE’ Name=’SharedWithUsers’ StaticName=’SharedWithUsers’ Group=’_Hidden’ Sealed=’TRUE’ AllowDeletion=’FALSE’ ReadOnly=’TRUE’ ShowInDisplayForm=’FALSE’ ShowInEditForm=’FALSE’ ShowInListSettings=’FALSE’ Viewable=’FALSE’ SourceID='{ 86ea65fd - 7aea - 4dd1 - afdb - bbbce3c16daa}’ />";

FieldCollection fields = web.AvailableFields;
IEnumerable<Field> filteredFields = context.LoadQuery(fields.Where(f => f.InternalName == "FieldName"));
   context.ExecuteQuery();

   SP.Field newField = filteredFields.FirstOrDefault();
   if (newField == null)
   {
   newField = CurrentList.Fields.AddFieldAsXml(SharedWithFieldDefXml, true, AddFieldOptions.AddFieldToDefaultView);
   web.Fields.Add(newField);
   context.Load(newField);
   context.ExecuteQuery();
   }

For more information see this thread.

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.