Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:

Recycle Bin | MMS | ManagedVsCrawledProperties |

Wednesday, June 6, 2012

Content Types in SharePoint

What is a Content type?
  • Content types are reusable collection of metadata.
  • Content types are available at site collections and site level. When you create a content type and add it to a site's content type collection, the new content type becomes available to any child site and also to the site where it was created.
  • You never create a content type from scratch. Instead, you always select an existing content type as the basis for any new content type that you create.
  • When you add a content type to list. Microsoft SharePoint foundation makes a local copy of site content type and adds the local copy to the list. This local instance is called "List Content type".
  • To add a content type to a list, you must have List Administrator rights to that list.

Why content types concept comes into the picture:

As per msdn why content types, For example, imagine a business situation in which you have three different types of documents: expense reports, purchase orders, and invoices. All three types of documents have some characteristics in common; for one thing, they are all financial documents and contain data with values in currency. Yet each type of document has its own data requirements, its own document template, and its own workflow. One solution to this business problem is to create four content types. The first content type, Financial Document, could encapsulate data requirements that are common to all financial documents in the organization. The remaining three, Expense Report, Purchase Order, and Invoice, could inherit common elements from Financial Document. In addition, they could define characteristics that are unique to each type, such as a particular set of metadata, a document template to be used in creating a new item, and a specific workflow for processing an item.

Scope of content types:
  • Content types are a site-scoped Feature. Content Type Features can be scoped only at a Site level.
  • Typically Content Types and Site Columns are Site scoped; you can't deploy using features to a web.
Content types inheritance:
  • In Content types, Inheritance concept is introduces in SharePoint 2010.
  • Inherited content types are not editable at the child level. Only way for editing is by using content type to list.
  • Content Types only holds the reference of Site Columns or fields but does not contain columns or fields itself. As a result, columns can only be referenced in a Content Types so columns need to be created separately.
  • If you remove any site column from site content type, then it will remove from site content type but the local copy/orphan column will not be deleted. Keep in mind that removing the site column from site content type is not the same as deleting it in the lists that use it already.
  • Suppose if you modify the site column from the site content type that changes will affect to all its inherited content types.
  • Reason: Site Columns are basically working as a template. It means whenever you attach any Site Columns to SharePoint list, a local copy of that site column (i.e. as list column) will be created. But interestingly SharePoint maintains the same field GUID for the above mentioned local copy or list column as well as for Site Column.
  • So now you can understand how the SharePoint apply any changes in Site Column to its local copy. Yes, SharePoint uses that field GUID to track which list columns/local copy of site columns are "children" of a given site column and based on that the changes propagates.
Few basic points to remember about content types:
  • The collection that is returned by the AvailableContentTypes property is read-only. This is because the collection includes not only the content types that are defined on the current site but also those that are defined on sites above it in the site hierarchy.
  • Content types that are created at the site level can be applied to child sites or lists.
  • In Microsoft SharePoint Foundation 2010, every item has a content type assigned to it, either implicitly or explicitly.
  • You can prevent users from making changes to specific content types in two ways, by using read-only content types and sealed content types. Each method has its advantages.
  • Should have list administrator permissions to updates changes to the content types.
  • The reference between Content Types and site Columns maintained using SPFieldLink (Microsoft.SharePoint.SPFieldLink).
  • You cannot delete a content type from a list if that list contains items of that content type.
  • Verify that the list can accept the content type that you have selected by calling the IsContentTypeAllowed(SPContentType) method.
  • Make sure the list accepts content types.
  • list.ContentTypesEnabled = true; Enable content types for the list by setting the value of the list’s ContentTypesEnabled property to true. In UI to enable content types go to list settings-->advanced settings--> Allow management of content type to "yes".
Difference between content types and site columns?

Site Columns store values. Each column stores values of particular type. Content Types are logical containers that consist of one or more Site Columns. Content Type itself doesn't store any content.
SPWeb.AvailableContentTypes vs. SPWeb.ContentTypes

  • Gets the collection of content types for the Web site.
  • The ContentTypes property returns only the content types that exist on the current Web site, not all content types in the current scope. Use the AvailableContentTypes property to return all content types in the current scope, including those of any parent Web sites. When you add a content type to this collection, you make it available to lists in the current Web site and in any child Web sites.
  • Gets the collection of all content types that apply to the current scope, including those of the current Web site, as well as any parent Web sites.
  • You can apply any content type that is returned in this collection to lists in the current Web site. However, you cannot add content types to the collection that is returned in this property. It is a read-only property. If you want to make a new content type available, you must add it to the collection that is returned by the ContentTypes property. That collection includes only the content types that exist in the current Web site.
Delete content type

If you are trying to remove a content type from the site collection where it is defined, you must be sure that the GetUsages method returns an empty list—that is, that the content type is not used on any list and is not the parent of any child content type. 

SPContentTypeUsage.GetUsages Method
  • Returns a list of SPContentTypeUsage objects with information about where the specified content type is in use.
  • This method returns a generic list of SPContentTypeUsage objects that contain information about each use of a content type in the site collection. If the content type is not used, the method returns an empty list (Count = 0).
  • we can not delete the parent content type if already in use but we can delete the used site columns.

Associate a workflow to the content type:

SPContentType.AddWorkflowAssociation to associate workflow to the content type
In order to associate workflow with a content type you have to change the AssociationCategories element value in the workflow’s Elements.xml file to ContentType.

Associate workflow to the content type in feature+event receiver

Add the event receiver to the content type:

Hope, I covered most of them on content types. Please add if i missed anything.

Thanks for reading this post.

1 comment:

  1. Thanks for a great explanation on Content types. I’m working with the Enterprise Wiki in Sharepoint 2010 and need to add a Table of Contents to list all wiki pages. Is it possible to autogenerate a TOC based on a Category Content type where Categories are assigned to each wiki page in the site?