Reprint SharePoint "Site Definition Series" – Create Content Type

Source: Internet
Author: User

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

SharePoint itself is a rich large container, all the information stored inside we can call it "content", in order to facilitate the management of these conent, according to human normal logic must think of this is "classification." The dimensions involved in classification must include:

1. The standard or characteristic description of the classification {i.e.: type attribute (or property associated with the type Item)}.

2. Associated actions for the corresponding class (i.e. workflow, behavior, and other settings) there is also a content type group on the organization of the content type, with each content type belonging to a different group.    We take things from home, for example, you can define different content types for your household items, such as books, kitchen utensils, and so on, even if they are home content. Book class related attributes can have book name, author name, ISBN, Book category, Publication date.    These attribute definitions are based on pre-defined public property descriptions (Site Columns), in the book class we can define related workflows eg: borrowing workflows, storing workflows ...., you can define the management forms to use when manipulating book classes, reading cards, etc... So, in SharePoint, as well as basically managing this logic, let's take a look at Microsoft's definition of the content type: contents types are Microsoft SharePoint Foundation 2010 A reusable collection of metadata (columns), workflows, behaviors, and other settings for a class of items or documents in a list or document library.    With content types, you can use a centralized, reusable way to manage settings for a class of information. That is, the content type is used to define the properties of the list item, the document file, or the Folders folder. Each type of content can be specified:

1. Properties associated with this type of project

2. Workflows that can be started from this type of project

3. Document templates (for document content types)

4. Available document conversions (for document content types)
5. Custom Functions

You can associate a content type with a list or library. When you do this, you are specifying that the list or library can contain items of this content type, and the new command in that list or library will allow users to create new items of this type.     SharePoint supports a document library associated with multiple content types. But for an item in the document library or list, allowing one and only one contenttype to relate to it, it's good to understand that a container can hold several categories of items, but an item can only belong to a certain category, and no one can cause management confusion.      A content type necessarily requires a set of properties that describe its characteristics. For example: Cat class, then you will have a set of characteristics to describe the cat class to distinguish other classes. Each attribute used to describe a feature occupies a field representation. Each field actually belongs to a site Column.     You can also associate a document template to a content type so that when you create an instance of such a content type, you can ask the user to fill out a document The document documents for the template are stored in the list together with the list item instance containing this conent type.     when creating a new contenttype, you'd better go to SharePoint pre-defined column Groups (eg:base Columns, Core contact and Calendar Columns, Core Document Columns, Core Task and Issue Columns, Custom Columns, Extended Columns) to find out if there is no ready-made site column for you to use, and not is anxious to create a new site column separately. The benefit of this is to maintain the consistency of the site column definition within the system and to facilitate future maintenance management.     Content type is organized hierarchically, and all ContentType have their parent ContentType, and if they modify their parent Content type, Then this change will be extended to these child ConTent Type, but vice versa. The hierarchical relationships of Content type are as follows:

As the graph shows, all the content type comes from item under System, and item is a hidden content type, which does not contain any column.

The Content type can be divided into the site Collection level and the list at the function range.    The previous level acts on the entire site Collection, and the latter level only works on a particular list. Since site columns is organized according to site Column Groups, content types is also organized according to the content type Groups, which is commonly used by the system content type Groups:

Document Content Types

folder Content Types

Group Work Content Types

List Content Types

Special Content Types

There are two ways to create a content Type

1. Create from SharePoint UI

2. Created by Visual Studio encoding here we look at how to create with VisualStudio encoding, first open VS2010, create a new project, use the content type template, solution named MyContentType1

Select New Solution for farm type

Make sure this new contenttype is based on the picture

New projects such as:

Our new content type will be defined in the Elements.xml of the ContentType1 point. Please enter the following code:

<!--Parent Contenttype:picture (0x010102)-<ContentTypeId= "0X01010200404203548FEA4E479B7684C563248C8B"Name= "Mycontenttype1-contenttype1"Group= "Custom Content Types"Description= "My Content Type"Version= "0"><Fieldrefs><!--Date Picture taken-<RemovefieldrefId= "{A5D2F824-BC53-422E-87FD-765939D863A5}"/><!--Picture Size-<RemovefieldrefId= "{922551b8-c7e0-46a6-b7e3-3cf02917f68a}"/><!--About Me-<FieldRefId= "{e241f186-9b94-415c-9f66-255ce7f86235}"DisplayName= "Information"/>           <!--cameral used-->            < Fieldref id= "{ B8A42D20-BE9C-48ED-AFC1-78BD48C523A9} " displayname = "cameral used" />        </fieldrefs >   </ contenttype>

Projects such as:

The code is described as follows:

I. Content type related properties

1, Content Type ID:

The ID of a content type is a unique identity that identifies the content type, which implies a hierarchy of content types, that is, from the content type ID, which is the parent content type that the content type inherits from, the content type ID contains the parent content type ID, and we can find the top-level system content type from the content type ID number.       WSS 3 uses this information in the ID number to determine the relationship between content types and to perform actions. A content type can be represented in either of two ways, whereas the system content type ID is "0x", and all other content types inherit from the system content type.         All other content type IDs must create an ID number in one of the two ways, and this ID number must be unique in the site collection, and here are the two representations: rule A, parent content type ID + two-bit hexadecimal value (two-bit hexadecimal value cannot be 00), such as: 0x0101 The content type IDs that WSS comes with are generated in this way. For example: The base Content type Item has an ID number of 0x01, which indicates that the type content of item 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, with these two ID numbers, we can see that Both the document content type and the folder content type inherit from the item content type, and the item content type inherits from the system content type

Rule B, parent content type ID + "00" + Hex GUID, such as: 0x010100d5c2f139516b419d801ac6c18942556d

WSS uses this type of rule to genetic content type IDs when creating content types in the following scenarios:

1. Create site content types based on other content types

2. When a site content type is added to a list, the site content type is copied to this list and generated as a list content type, and the resulting content type ID

It is recommended to use the content type ID of the GUID method in the following cases:

1, inherited from the system default content type, such as document content type

2, inherit the content type developed by the third party, use the content type ID of the GUID, can guarantee the content type unique, and will not follow the future developer inherits this third party control to generate new content type ID duplicates

Once you have defined the ID of a content type with a GUID, you can still use the first way to name the type that inherits from this content type. The GUID that is used in the ID can serve as the role of the namespace, and any type that inherits from this content type can be prefixed with a two-bit hexadecimal value to represent the new ID, such as "0x010100d5c2f139516b419d801ac6c18942556d"

The content type ID has a maximum length of 512 bytes, because one byte can hold two hexadecimal values, so a content type ID can use up to 1024 characters.

Is the contenttype of some systems and their ID tables

Here are some examples of content Type IDs

1. Create a content type, its GUID {0bb3f82d-2a62-4b77-833c-28045f765d7b}, and its parent is contact (0x0106), then you can set its ID as follows: 0x0106000bb3f82d2a624b77833c28045f765d7b 2. Create a content type, its GUID {0e3e8f35-3a21-4ed7-8151-816c48e2d64d}, Its parent is document (0X0101), then you can set its ID as follows: 0X0101000E3E8F353A214ED78151816C48E2D64D 3. Create a content type whose GUID { A6c62a39-e374-4d8d-9efe-90dd65b659f8}, whose parent is Item (0x01), then you can set its ID as follows: 0x0100a6c62a39e3744d8d9efe90dd65b659f8

2. The Name property of the content type: is the name of the tag we gave this content type

3. The Group property of content type: We divide this content type into which group of content Type group, that is, group manages our content type

4. Description property of Content type: Description of this content type

5. Inherits property of Content type: This property is used in conjunction with the <RemoveFieldRef> element we are talking about, if interits= ' True ' is set here, then < Removefieldref> won't work. Therefore, we need to take out its settings.

6. Version property of Content type : defines its revision number

Ii. content of <FieldRefs> elements

The contents of the content type that we really define are within the <FieldRefs> element, and here we explain

1, <RemoveFieldRef> elements: This element defines the field that we want to remove

Since our new Content type is inherited from the picture, it has all the field of the parent Content type Picturey, the inheritance relationship, but here we don't want to inherit from the picture "Date Picture taken "and" picture Size "These two field, so we need to do the work include:

A. Removing the Inherits property of the content type

B. Add <RemoveFieldRef> elements

Because if the inherits property of the content type is set to ture, no matter where we set any removefieldref elements, they will not work, and the system will force the newly created contenttype to inherit all of its parent The content type has the fields, so we have to break the inheritance relationship between our newly defined content type and its parent:picture.

The next step is how do we know what field they have ID values we want to cancel?

We can use the Server Exploer tool in VS2010, and when we use the Server Exploer tool to establish a connection to a SharePoint site, we can see the various objects of this site

Expand the ContentType node, locate the picture node, and then you can see the ID number of the corresponding field, which you can copy directly into this solution.

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

In this example, we have added two fields, one is the system's original site Column, called about Me, the way to get its ID is as follows: using the server Exploer

We gave it a new displayname= "information about this", and this displayname will be displayed on the Admin UI interface of the SharePoint content type.

<!--about Me-- <FieldRef ID= "{e241f186-9b94-415c-9f66-255ce7f86235}" DisplayName= "information about this"/>

We add or remove the above is the system already exists site Columns, if we want to operate the site column does not exist, we can either create the SharePoint UI through the site column, you can also through the visual Studio2010 to create, specific methods reference this article SharePoint learning Notes-site Definition Series--Create Site Columns

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

You can see that our new content type already appears in the expected location

And its content is what we define here (remove two fields, add two fields, one of which is the system comes with, one we developed with VS2010 above)

Reprint SharePoint "Site Definition Series" – Create Content Type

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.