Content Type
Content Types are the building blocks of site columns and
content types defines the schema of the fields of list item ,Content types helps in reusing the site columns across the
site collection, we can create content types and attach these
How to navigate Content Type page
Content types to site columns to create content type
navigate to site settings page and click on site content types.
To view the list of available content types of a site
collection you can directly navigate to the page "mngctype.aspx"
Content Type scope
Content types can be created based on site collection or
inside child site of a site collection
The following shows the lists Ids associated with each type
of list/templates of the list
Parent
|
Name
|
Id
|
Item
|
Document
|
0x0101
|
Item
|
Announcement
|
0x0104
|
Item
|
Task
|
0x0108
|
System
|
Item
|
0x01
|
Item
|
Link
|
0x0105
|
Item
|
Contact
|
0x0106
|
Item
|
Event
|
0x0102
|
Folder
|
Summary Task
|
0x012004
|
Document
|
Picture
|
0x010102
|
Folder
|
Discussion
|
0x012002
|
Document
|
Form
|
0x010101
|
Document
|
Wiki Page
|
0x010108
|
Document
|
Basic Page
|
0x010109
|
Document
|
Master Page
|
0x010105
|
Using AvailableContentTypes
If you want to know the avaible content type using code you can use "AvailableContentTypes" SPWeb site = SPContext.Current.Web; // iterate content types for current site and parent sites too foreach (SPContentType myctype in site.AvailableContentTypes) { }Create content type programmatically
The following code demonstrate how to create content type programmatically
Sample code:
//access the web of the site collection
SPWeb site = SPContext.Current.Site.RootWeb;
//create content type name
string myctypeName = "hey my content test";
//access parent
SPContentType myctypeParent =
site.ContentTypes["Item"];
//create content type
SPContentType myctype = new SPContentType(myctypeParent,
site.ContentTypes, myctypeName);
//assigned the description and create a group
myctype.Description = "I am doing content type
programatically";
myctype.Group = "My Content Type Group";
//Add to site collection
site.ContentTypes.Add(myctype);
No comments:
Post a Comment