Defining Custom Folder content type and custom document content type
A Two Part Article Series
Part 1 : It would be about creating fields and custom content type for document and one
for folder. Then creating a feature to bind them together and activate on a site collection.
Part 2 : This would explain about you can associate those content types programmatically
with a document library.
Here we begin with Part 1
Note : Whereever you see Guids, replace them with new ones on your machine.
First we create a few fields that we can use in our custom content type
Create a file myfields.xml and paste this content in it :
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- first two fields are for creating custom document content type -->
<Field Type="Text" DisplayName="File Checksum" Required="FALSE" MaxLength="255"
Group="MyGroup" ID="{01837735-8dec-4f20-b725-5d05e8747f60}" SourceID="{89369214-f359-419c
-80de-14763a3fd415}" StaticName="FileChecksum" Name="FileChecksum" ShowInNewForm="FALSE"
ShowInEditForm="FALSE" ShowInFileDlg="FALSE"></Field>
<Field Type="Note" DisplayName="Information" Required="FALSE" NumLines="6" RichText="TRUE"
RichTextMode="Compatible" AppendOnly="TRUE" Sortable="FALSE" Group="MyGroup"
ID="{f48d6644-70ff-402c-847f-728f388d19b7}" SourceID="{89369214-f359-419c-80de-
14763a3fd415}" StaticName="Information" Name="Information"></Field>
<!-- folder status field used by Custom Folder -->
<Field Type="Choice" DisplayName="Status" Required="TRUE" Format="Dropdown"
FillInChoice="FALSE" Group="MyGroup" ID="{61CA18AF-307D-4e08-9907-0274ECABEE56}"
SourceID="{89369214-f359-419c-80de-14763a3fd415}" StaticName="CustomFolderStatus"
Name="CustomFolderStatus">
<Default>Not Started</Default>
<CHOICES>
<CHOICE>Not Started</CHOICE>
<CHOICE>In Progress</CHOICE>
<CHOICE>Completed</CHOICE>
</CHOICES>
</Field>
</Elements>
Now we create another file ctypesCustomDocument.xml and paste this content in it :
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x010100F2895C5AACCB5A4599ACEF15F4E082D3" Name="My Custom Doc Type"
Group="MyGroup" Version="1">
<FieldRefs>
<FieldRef ID="{f48d6644-70ff-402c-847f-728f388d19b7}" Name="Information"
Required="FALSE"/>
<FieldRef ID="{01837735-8dec-4f20-b725-5d05e8747f60}" Name="File Checksum"
Required="FALSE"/>
</FieldRefs>
</ContentType>
</Elements>
Then create a file ctypesCustomFolderType.xml and paste this content in it :
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<ContentType ID="0x01200051F2CB82D79099439C4C3AF20A5517B5" Name="My Custom Folder Type"
Group="MyGroup" Version="0">
<FieldRefs>
<FieldRef ID="{61CA18AF-307D-4e08-9907-0274ECABEE56}" Name="Status" Required="TRUE"
/>
</FieldRefs>
<XmlDocuments>
<XmlDocument
NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates
xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>ListForm</Display>
<Edit>ListForm</Edit>
<New>ListForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>
</ContentType>
</Elements>
So just to re-iterate what we have done till here is :
Create a custom document type called “My Custom Doc Type” that includes two field
“Information” and “File Checksum”.
Create a custom folder content type called “My Custom Folder Type” this includes one field
“Status” which is a choice field.
Now we create a feature.xml file and put references to these three xml files in that one
file.
Copy this xml in feature.xml file :
<Feature xmlns="http://schemas.microsoft.com/sharepoint/" Id="52143C47-C82C-40af-873C-6C9E52E9C73D" Title="Custom Content Types" Description="Installs Custom Content Types" Version="1.0.0.0" Scope="Site" DefaultResourceFile="core" Hidden="false" > <ElementManifests> <ElementManifest Location="myfields.xml"/> <ElementManifest Location="ctypesCustomDocument.xml"/> <ElementManifest Location="ctypesCustomFolderType.xml" /> </ElementManifests> </Feature>
Now copy all the 4 files we have created till now into 12-
hive/TEMPLATE/FEATURES/CustomContentTypes
Install the content types using this command (you would have to add stsadm to your path
variable for this to work)
stsadm -o installfeature -name CustomContentTypes -force
Once it is installed, we see how it can be used in the next article of this series.

[...] on creating a custom document library and attaching the custom types to the list, I would have a separate post for creating those custom content [...]
Pingback by Programmatically adding Custom folder and Custom document type in SharePoint document library « Prash's Blog | July 14, 2009 |