SPContentTypeId.ToString Method
Returns a string of hexadecimal characters that represents the content type identifier (ID).
Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Syntax
'Declaration
Public Overrides Function ToString As String
'Usage
Dim instance As SPContentTypeId
Dim returnValue As String
returnValue = instance.ToString()
public override string ToString()
Return Value
Type: System.String
A string that represents the content type ID. The first two characters of the string are always "0x".
Remarks
The string returned by this method can be a useful tool for understanding the recursive nature of content type IDs. For example, the following code gets the content type ID from a list content type, and uses that ID to determine the IDs for the content types three generations back. When it has collected all four IDs, the application prints their string values to the console.
SPContentTypeId child = web.Lists["Announcements"].ContentTypes["Announcement"].Id;
SPContentTypeId parent = child.Parent;
SPContentTypeId grandparent = parent.Parent;
SPContentTypeId greatgrandparent = grandparent.Parent;
Console.WriteLine("Greatgrandparent id: {0}", greatgrandparent.ToString());
Console.WriteLine(" Grandparent id: {0}", grandparent.ToString());
Console.WriteLine(" Parent id: {0}", parent.ToString());
Console.WriteLine(" Child id: {0}", child.ToString());
Dim child As SPContentTypeId = web.Lists("Announcements").ContentTypes("Announcement").Id
Dim parent As SPContentTypeId = child.Parent
Dim grandparent As SPContentTypeId = parent.Parent
Dim greatgrandparent As SPContentTypeId = grandparent.Parent
Console.WriteLine("Greatgrandparent id: {0}", greatgrandparent.ToString())
Console.WriteLine(" Grandparent id: {0}", grandparent.ToString())
Console.WriteLine(" Parent id: {0}", parent.ToString())
Console.WriteLine(" Child id: {0}", child.ToString())
This code prints the following output to the console.
Greatgrandparent id: 0x
Grandparent id: 0x01
Parent id: 0x0104
Child id: 0x0104009010BFF57D431540B197B8058EBC3035
For more information about how content type IDs are formed, see Content Type IDs.
See Also
Reference
Microsoft.SharePoint Namespace