SharePoint Object Model has the lot of in-build hidden gems that helps to identify the information from the SharePoint objects. Here, we are going to see the methods, which helps us to check whether the field is available under the Field collection based on different parameters.
SPFieldCollection has the below methods which returns Boolean value based on the given input to their appropriate methods.
Method | Method Available | Description |
bool SPFieldCollection.ContainsField ( string <fieldname> ) | WSS 3.0 + | Returns true, if the field is available in the field collection based on given string. The given string may be a display name or internal name of a field. |
bool SPFieldCollection.Contains ( Guid <fielded> ) | SharePoint 2010 + | Returns true, if the field available in the field collection based on given guid. The given guid is a id of the field |
bool SPFieldCollection.ContainsFieldWithStaticName ( string <fieldname> ) | SharePoint 2010 + | Returns true, if the field available in the field collection based on the field’s static name. |
We can also find the field is available in the SPFieldCollection object by using the following Constructors.
SPField SPFieldCollection [ <field id> ]
SPField SPFieldCollection [ <field index> ]
SPField SPFieldCollection [ <field display name> ]
But it also throws the error, if the field is not available based on the given parameter. And it also affects the performance when compared to the methods.
So, always identify and go with the best practices, which is hidden in lot of SharePoint objects.