Last time one of my Clients asked me for a possibility to extend document libraries with Excel template. The choice was obvious – a custom content type with Excel document template. I have created such a content type in few minutes, created a package, run deployment process and… Voilà! Site content type has been created.


<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
 <!-- Parent ContentType: Document (0x0101) -->
 <ContentType ID="0x0101007854B51762FA4A7C92E8568CE37E5A5C"
 Name="Excel"
 Group="Document Templates"
 Description="Excel"
 Inherits="TRUE"
 Version="0">
 <FieldRefs>
 </FieldRefs>
 <DocumentTemplate TargetName="Excel.xltx"></DocumentTemplate>
 </ContentType>
 <Module Name="ExcelTemplate" Url="_cts/Excel">
 <File Type="Ghostable" Url="Excel.xltx" Path="Excel/Excel.xltx"></File>
 </Module>
</Elements>

To make some tests, I have added it to a document library and created a new document. At this point everything seemed to be OK.

NewExcelCT

After a few clicks I noticed that content type of my newly created Excel file was set to Document instead of Excel.

ExcelDocDisplay

ExcelDocEdic

I double checked content types’ xml definition, any errors during deployment process, but I did not found anything special. Some time later I noticed, that when I reassign the document type from the UI, content type starts working properly. Thanks to that I came up with a simple solution – I added a feature receiver in which I reassing the document template:


public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
SPSite site = properties.Feature.Parent as SPSite;
SPContentType ctExcel = site.RootWeb.ContentTypes["Excel"];
ctExcel.DocumentTemplate = ctExcel.DocumentTemplate;
ctExcel.Update();
}

That fixed the problem!

ValidExcelDoc