Thursday 22 December 2011


content type in Share point 2010


content type is a reusable collection of metadata (columns), workflow, behavior, and other settings for a category of items or documents in a Microsoft SharePoint Server 2010 list or document library.

Lists and document libraries can store different kinds of content, known as content types.Content types can use site columns only for column definitions. This means that to create a content type, you must choose what site columns should be included in that content type.

You can create a content types with either Out-of-Box option available in your SharePoint Site or by using Client and Server Object models.

1) To create one in your SharePoint 201o site, follow the steps below:
1. Click Site Actions ➪ Site Settings.
2. Under Galleries click on “Site content types” and then click Create. See the Screen below.



3. Next Click on “Create” and Provide Name and Description on “New Site Content Type” Page. Next,    from “Parent content type from” Drop-down select “List Content Types” and from “Parent content type” select “Issue” type. In Group select “custom content types” or select a new group and give it a name.
4. When the content type is created, you can see that in “Custom Content types”.
5.  Click on the “Test Content Type”  and you can chnage various options like Title, description etc and also can add additional Site columns which get carried along with this content type.

6. Now either you can create a new list or navigate to an existing one with which you want to associate the custom template(content type).
7. After you navigate to the new list, on the ribbon click the list tab and then list Settings.
8. Click Advanced Settings and then click Yes for the “Allow management of content types?” button and click Ok.
9. Click OK to return to the new list’s settings page.
10. On the Advanced Settings page, click the “Add from existing site content types” link to add your new content type to the the custom list. In the Available Site Content Types list, find the custom content type you created, and then click the Add button to move that content type into the “Content types to add” list.
11. Now you can navigate to your list and click New . Your custom Content Type  will be in the drop-down for your selection.


Steps to create a Content type using Client object model are
1. To create a content type using the client object model in Visual Studio 2010, create a new project (File ➪ New ➪ Project) and select a Console project template.
2. After the project starts, you will add references to the Microsoft.SharePoint.Client.dll and Microsoft.SharePoint.Client.Runtime.dll assemblies located in the 14\ISAPI folder also listed under the .NET component listing in the Add References dialog box.
3. Next, write the code below in you main method. Please note that unlike, server object model, client object model makes use of an Information class that contains the template of the content type. The information class works in a similar manner to the SPContentType class with the exception of the parent ’ s reference; rather than pass in a reference to the parent ’ s content type, client object model code gets the parent ’ s ID.
static void Main(string[] args)
{
// Get a reference to the site collection
ClientContext clientContext = new ClientContext(“http://SPsite”);
Web web = clientContext.Web;
// Load reference to content type collection
ContentTypeCollection contentTypes = web.ContentTypes;
clientContext.Load(contentTypes);
clientContext.ExecuteQuery();
// Create a Content Type Information object
ContentTypeCreationInformation _customcontenttype = new ContentTypeCreationInformation();
customcontenttype.Name = “Custom Content type”;
customcontenttype.ParentContentType = contentTypes.GetById(“ADD PARENT CONTENT TYPE ID”);
customcontenttype.Group = “Custom content type group”;
// Create the content type
ContentType myContentType= contentTypes.Add(customcontenttype);
clientContext.ExecuteQuery();
}
4. After the Information object is completed, a ContentType object is added to the ContentTypes collection that you loaded with the ClientContext using the Information objec



No comments:

Post a Comment