Export (0) Print
Expand All

SPBuiltInContentTypeId Class

Windows SharePoint Services 3

A class that retrieves SPContentTypeId objects that represent identifiers (IDs) for built-in content types.


Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel = true)]
public sealed class SPBuiltInContentTypeId

You can use the fields of this class in a way that is similar to the way that you use members of an enumeration.

The following example shows a console application that finds both the common parent of two content type IDs and the name of the parent content type. It also prints the result to the console.

using System;
using Microsoft.SharePoint;

namespace Test
   class ConsoleApp
      static void Main(string[] args)
         using (SPSite site = new SPSite("http://localhost"))
            using (SPWeb web = site.OpenWeb())
               SPContentTypeId x = SPBuiltInContentTypeId.Message;
               SPContentTypeId y = SPBuiltInContentTypeId.Discussion;

               // Get the parent content type ID.
               SPContentTypeId parentId = SPContentTypeId.FindCommonParent(x, y);
               // Get the parent content type name.
               SPContentType ct = web.AvailableContentTypes[parentId];
               string parentName = ct.Name;

               // Display the result.
               Console.WriteLine("ID of Message is       {0}", x.ToString());
               Console.WriteLine("ID of Discussion is    {0}", y.ToString());
               Console.WriteLine("Their common parent is {0} ({1})", 
                                  parentId.ToString(), parentName);
         Console.Write("\nPress ENTER to continue...");

The application prints the following output to the console.

ID of Message is       0x0107
ID of Discussion is    0x012002
Their common parent is 0x01 (Item)

Press ENTER to continue...

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions

© 2014 Microsoft