SPBuiltInFieldId.Contains Method

Returns a Boolean value that indicates whether or not the specified GUID matches the ID for a built-in field.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
Public Shared Function Contains ( _
    fid As Guid _
) As Boolean
'Usage
Dim fid As Guid
Dim returnValue As Boolean

returnValue = SPBuiltInFieldId.Contains(fid)
public static bool Contains(
    Guid fid
)

Parameters

Return Value

Type: System.Boolean
true if the GUID matches the ID of a built-in field; otherwise false.

Examples

The following example is a console application that calls the Contains method twice: first, to verify whether an arbitrary member of the site columns collection is a built-in field; second, to prove that a newly-created field is not a built-in field.

using System;
using Microsoft.SharePoint;

namespace Test
{
   class Program
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://localhost"))
         {
            using (SPWeb web = site.RootWeb)
            {
               // Test a field from the site columns collection.
               SPField siteField = web.Fields[0];
               FieldTest(siteField);

               // Create a field and test it.
               SPField newField = new SPField(web.Fields, SPFieldType.Boolean.ToString(), "New Field");
               string internalName = web.Fields.Add(newField);
               newField = web.Fields.GetFieldByInternalName(internalName);
               FieldTest(newField);
            }
         }
         Console.Write("\nPress ENTER to continue...");
         Console.Read();
      }

      static void FieldTest(SPField field)
      {
         if (field == null)
             throw new ArgumentNullException("field");

         Guid fid = field.Id;
         Console.WriteLine("The field {0} {1} a built-in field.",
             field.InternalName, SPBuiltInFieldId.Contains(fid) ? "is" : "is not");
      }
   }
}
Imports System
Imports Microsoft.SharePoint

Namespace Test
   Friend Class Program
     Shared Sub Main(ByVal args() As String)
       Using site As New SPSite("https://localhost")
         Using web As SPWeb = site.RootWeb
            ' Test a field from the site columns collection.
            Dim siteField As SPField = web.Fields(0)
            FieldTest(siteField)

            ' Create a field and test it.
            Dim newField As New SPField(web.Fields, SPFieldType.Boolean.ToString(), "New Field")
            Dim internalName As String = web.Fields.Add(newField)
            newField = web.Fields.GetFieldByInternalName(internalName)
            FieldTest(newField)
         End Using
       End Using
       Console.Write(vbLf & "Press ENTER to continue...")
       Console.Read()
     End Sub

     Private Shared Sub FieldTest(ByVal field As SPField)
       If field Is Nothing Then
          Throw New ArgumentNullException("field")
       End If

       Dim fid As Guid = field.Id
       Console.WriteLine("The field {0} {1} a built-in field.", field.InternalName,If(SPBuiltInFieldId.Contains(fid), "is", "is not"))
     End Sub
   End Class
End Namespace

See Also

Reference

SPBuiltInFieldId Class

SPBuiltInFieldId Members

Microsoft.SharePoint Namespace