SharePoint - Content Type ID's(转)
SharePoint - Content Type ID's
Content types are little gems within SharePoint with many useful characteristics. The one characteristic is that content types support inheritance. For the non programmers; inheritance is when you define a content type it must be based on an existing content type. The new type called the child type will get all the features, i.e. fields, settings of the parent type. The child type can then have additional types.
To illustrate this, let us say we have a business that has customers and suppliers and we need to store customers and suppliers. We could easily create a content type for a Customer that inherits from Contact, however a customer has an additional Account number field and Account Manager field. The Supplier is also a contact and thus inherits from contact, however it has a Customer Number field.
At this point it is important to note that content types inherit from other content types and build a tree as shown in the diagram below:
You can create your own content types that inherit from other content types in CAML by understanding the ID field. Each content type must have a unique id, however unlike many other ID's that are Globally unique identifiers, a content type ID is a mixture of the parent ID, shown in the table below an a unique GUID. Also the GUID is contains no braces or dashes like other GUIDS.
Content Type
| ID Start
|
System
| 0x
|
Item
| 0x01
|
Library Content Types
|
|
Document
| 0x0101
|
Form
| 0x010101
|
Picture
| 0x010102
|
WikiDocument
| 0x010108
|
BasicPage
| 0x010109
|
WebPartPage
| 0x01010901
|
List Content Type
|
|
Event
| 0x0102
|
Issue
| 0x0103
|
Announcemnt
| 0x0104
|
Link
| 0x0105
|
Contact
| 0x0106
|
Message
| 0x0107
|
Task
| 0x0108
|
BlogPost
| 0x0110
|
BlogComment
| 0x0111
|
Folder Content Types
|
|
Folder
| 0x0120
|
RootOfList
| 0x012001
|
Discussion
| 0x012002
|
Where to set the ID
When you define your content type in the Elements manifest file, there is a mandatory ID field which needs to be the content type. A snipit of a content type is shown below:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType
ID="0x0106000BB3F82D2A624B77833C28045F765D7A"
>
</ContentType>
</Elements>
The syntax is :
Parent ID + 00 + GUID
Examples
- To create a content type with GUID {0BB3F82D-2A62-4b77-833C-28045F765D7A} that is based on contact (0x0106), you would se the ID to
0x0106000BB3F82D2A624B77833C28045F765D7A - To create a content type with GUID {0E3E8F35-3A21-4ed7-8151-816C48E2D64F} that is a based on document (0x0101), you would set the ID to
0x0101000E3E8F353A214ED78151816C48E2D64F - To create your own item with GUID {A6C62A39-E374-4d8d-9EFE-90DD65B659F9} that is based on item (0x01), you would set the ID to
0x0100A6C62A39E3744D8D9EFE90DD65B659F9