Tuesday, May 20, 2008

How to add Content Type through Feature?

Hi all,
Here is the way how to create a Content type through feature.

Steps:
1) Create a feature (I hope you know how to create a feature or go to this MSDN link.)
2) In element.xml add following xml tag

<ContentType
ID="0x010100BC4AA99D05D3488e95993BA063E6F6A2"
Name="Name of Content Type"
FeatureId="{E282F40C-1ECD-47d7-9E6A-BD3FBDA8500C}"
Description="Description of Content Type"
Group="Your Own Group"
Version="1">
<DocumentTemplate TargetName="your template.doc" />
</ContentType>
<Module Name="Name of Content Type"
SetupPath="Features\Feature_ContentTypes" Path=""
Url="_cts/Name of Content Type">
<File Url="your template.doc" />
</Module>

3) Explanation of this tag,
ID = new generated content type ID [0x010100<NEW GUID without hyphen>]
FeatureId = feature id used in feature.xml
Group = your group name if group exist then it will create a new group in content type.
DocumentTemplate = name of your document/excel template

4) Module will relate your template to content type.
Name = name of your content type. Same as content type name.
SetupPath = relative path for physical template as we are putting our template in feature folder.
Path= no need to give as we are using SetupPath.
Url = all the content type template wil be saved in _cts folder. You can see this folder in sharepoint designer only. After “_cts/<Name of content type>” shold be same as Module name and ContentType name.
File Url = this will be name of document.


All done.
Only need to install the feature and activate the feature.

You can refer How to add document library with folders and content types through feature/site definition.

1 comment:

stefh said...

I've created a small tool to generate a feature which contains multiple contenttypes and document templates.

See http://spfg.codeplex.com/

Comments and tips are welcome!




Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com