SharePoint [site definition series]-02. Create content type

Source: Internet
Author: User

SharePoint itself is a rich large container. All the information stored in it can be called "content". To facilitate the management of these conents, according to the normal human logic, we must think of "classification ". Classification involves the following layers:
1. Standard or feature description of classification {that is, type attribute (or: attribute associated with this type of item )}.
2. associated actions of the corresponding class (workflow, behavior, and other settings)
There is also a content type group in the content type organization. Each content type belongs to different groups.
Let's take home things as an example. Various items in your home are the content of your home. You can define different content types for them, such as books and kitchen utensils.
The attributes involved in the book category can include the book name, author name, ISBN, book category, and publication date. These attribute definitions are based on the pre-defined site columns. In the document class, we can define the relevant workflow eg: borrowing workflow, keeping workflow ...., you can define the management forms, reader cards, and so on used when operating the books .......
Therefore, it is also basically managed according to this logic in Sharepoint. Let's look at Microsoft's definition of content type:
Content type)Is a reusable set of metadata (columns), workflows, behaviors, and other settings for a category of projects or documents in the Microsoft SharePoint Foundation 2010 list or document library. With the help of content types, you can use centralized reusable methods to manage the settings of a class of information.

That is, the content type is used to define the attributes of list item, document, or folder. You can specify each content type:
1. attributes associated with this type of project
2. workflow that can be started from this type of project
3. Document Template (for document content types)
4. Available document conversion (for document content types)
5. Custom Functions
You can associate the content type with the list or library. When you perform this operation, it means that you are specifying a list or a library that can contain this type of content, the "New" command in the list or library allows you to create a new project of this type.
SharePoint supports a document library to associate multiple content types. however, for an item in the document library or list, one and only one contenttype can be associated with it. This is easy to understand. For example, a container can store several types of items, however, an item can only belong to one category. Otherwise, management confusion may occur.
A content type must have a set of attributes that describe its features. For example, for cats, you need to have a set of features to describe cats to distinguish other classes. Each attribute used to describe a feature occupies one field. Each field actually belongs to a site column.
You can also associate a document template with a content type. In this way, when you create an instance of this content type, you can ask the user to enter a document based on this document template at the same time, together with the list item instance containing this conent type, it is stored in the list.
When creating a new contenttype, you 'd better go to the pre-defined column groups (eg: Base columns, core contact and calendar columns, core document columns, core task and issue columns, in custom columns, extended columns), check whether there is any existing site column for your use, instead of urgently creating a new site column. in this way, it is convenient to maintain the consistency defined by the site column in the system and maintain and manage the site column in the future.
Content type is organized according to the hierarchy. All contenttypes have their parent contenttype. If you modify their parent content type, such changes will include the Child content type, but vice versa. The hierarchical relationship of content type is as follows:


As shown in the figure, all content types come from items in the system, while item is a hidden content type, which does not contain any columns.

Content type can be divided into site collection level and list level according to the scope of action. The previous level acts on the entire site collection, and the next level only acts on a specific list.
Since site columns are organized according to site column groups, content types is organized according to content type groups. below is the commonly used content type groups in the system:
• Document content types
• Folder content types
• Group work content types
• List content types
• Special content types

We can create content type in two ways.
1. Create through SharePoint UI
2. Create with Visual Studio Encoding
Let's take a look at how to create a project using Visual Studio encoding. First, open vs2010 and create a project. Use the content type template, and name solution mycontenttype1.

Select the new solution as farm type

Make sure that the new contenttype is based on picture.

Create a project as follows:

 

The new content type is defined in elements. xml at contenttype1. Enter the following code:

<! -- Parent contenttype: Picture (0x010102) -->
<Contenttype id = "0x01010200404203548fea4e479b7684c563248c8b"
Name = "mycontenttype1-contenttype1"
Group = "Custom content types"
Description = "My content type"
Version = "0">
<Fieldrefs>
<! -- Date picture taken -->
<Removefieldref id = "{a5d2f824-bc53-422e-87fd-765939d863a5}"/>
<! -- Picture size -->
<Removefieldref id = "{922551b8-c7e0-46a6-b7e3-3cf02917f68a}"/>
<! -- About me -->
<Fieldref id = "{e241f186-9b94-415c-9f66-255ce7f86235}" displayname = "information about this picture"/>
<! -- Cameral used -->
<Fieldref id = "{B8A42D20-BE9C-48ED-AFC1-78BD48C523A9}" displayname = "cameral used"/>
</Fieldrefs>
</Contenttype>

Projects such:

The code is described as follows:

1. content type attributes

1. content type ID: content type ID

The content type ID is the unique identifier used to identify the content type. It implies the Parent-Child inheritance relationship of the content type, that is, the content type ID shows the parent content type inherited from this content type. The content type ID contains the parent content type ID, we can find the top-level system content type from the content type ID.
WSS 3 uses the information in the ID to determine the relationship between content types and perform operations.
The content type can be expressed in either of the two methods. The system content type ID is "0x", and all other content types are inherited from the system content type. All other content types must use one of the above two methods to create an ID number, and this ID number must be unique in the site set. The following are the two Representation Methods:
Rule A, parent content type ID + two hexadecimal values (two hexadecimal values cannot be 00), such as: 0x0101
The content type IDs of WSS are generated in this way. For example, if the ID of an item of the basic content type is 0x01, this ID indicates that the content of the item type is directly inherited from the system content type. The ID number of the document content type is 0x0101, And the ID number of the folder content type is 0x0120, we can see that both the document content type and folder content type inherit from the item content type, while the item content type inherits from the system content type.

Rule B. Parent content type ID + "00" + hexadecimal guid, for example, 0x010100d5c2f139516b419d801ac6c18942556d

WSS uses this rule to generate content type IDs when creating content types in the following situations:

1. Create a website content type based on other content types

2. When a website content type is added to a list, the system copies the website content type to this list and generates the list content type. The generated content type ID

In the following situations, we recommend that you use the guid content type ID:

1. inherit from the default content type of the system, such as the document content type

2. inherit from the content type developed by a third party. Use the guid content type ID to ensure that the content type is unique, it will not be the same as the new content type ID generated by the third-party control inherited by future developers.

After you define a content type ID using guid, you can still use the first method to name the type inherited from this content type. The GUID in the ID can assume the role of the namespace. Any type inherited from this content type can be added with two hexadecimal values to represent the new ID, for example, "0x010100d5c2f139516b419d801ac6c18942556d08"

The maximum length of a content type ID is 512 bytes. Because one byte can store two hexadecimal values, a content type ID can contain up to 1024 characters.

Is the contenttype and ID table of some systems

Here are some examples of content type ID

1. Create a content type with guid {0bb3f82d-2a62-4b77-833c-28045f765d7b} and its parent is contact (0x0106). Then, you can set its ID as follows:
0x00000000bb3f82d2a624b77833c28045f765d7b
2. Create a content type with guid {0e3e8f35-3a21-4ed7-8151-816c48e2d64d} and its parent is document (0x0101). Then, you can set its ID as follows:
0x0101000e3e8fda-a214ed78151816c48e2d64d
3. Create a content type, its guid {A6C62A39-E374-4d8d-9EFE-90DD65B659F8}, its parent is item (0x01), then you can set its ID as follows:
0x0100a6c62a39e3744d8d9efe90dd65b659f8

2. Name attribute of content type:Is the identifier we set for this content type.

3. Group attribute of content type:We divide this content type into which group of content type group, that is, group management of our content type

4. description attribute of content type:Description of this content type

5. inherits attributes of content type:This attribute should be used in conjunction with the <removefieldref> element described later. If interits = 'true' is set here, <removefieldref> will not work. Therefore, we need to remove its settings.

6. Version attribute of content type: Define its version number

Ii. <fieldrefs> element content

<Fieldrefs> the content of content type is defined in the element.

 1. <removefieldref> elements:This element defines the field we want to remove

Because the new content type is inherited from picture, it owns all fields of the parent content type of picturey, that is, the inheritance relationship, but here, we do not want to inherit the "Date picture taken" and "picture size" fields from picture, so we need to do the following work:

A. Remove the inherits attribute of content type

B. Add the <removefieldref> element.

Because if the inherits attribute of content type is set to true, no removefieldref element is set here, the system will force the newly created contenttype to inherit all the fields of its parent content type, so we must break the newly defined content type and its parent: the inheritance relationship between picture.

Next, how do we know the ID values of the fields we want to cancel?

We can use the server exploer tool in vs2010. When we use the server exploer tool to establish a connection with a Sharepoint website, we can see various objects of this website.

Expand the contenttype node, find the picture node, and then you can view the ID number of the corresponding field, which can be copied directly to this solution.

 

 

2. <fieldref> elements:Define the new field we want to add

In this example, we add two fields. One is the original site column named about me in the system. The method for obtaining the ID is the same as above: Use server exploer

We gave it a new displayname = "information about this picture". This displayname will be displayed on the SharePoint content type management UI.

<! -- About me -->
<Fieldref id = "{e241f186-9b94-415c-9f66-255ce7f86235}" displayname = "information about this picture"/>

We have added or removed the existing site columns in the system. If the site column we want to operate does not exist, what should we do? We can use the SharePoint UI to create the site column, you can also use visual studio2010 to create a table. For more information, see SharePoint Study Notes-site definition series-create site columns.

Next, build and deploy this solution, and go to the SharePoint site to view it.

 

We can see that the newly added content type has already appeared in the expected position.

 

And its content is exactly what we define here (remove two fields and add two fields, one of which is the system's own and the other is developed using vs2010)

Reprinted: http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.