Wednesday, May 28, 2008

Site Definition Fails to Use My Custom Home Page

Here's a minor annoyance that doesn't causes any in-your-face error messages, but can lead to a few deep frowns.

A MOSS site created from my custom site definition failed to apply my custom master page to the default.aspx page. The MasterPageFile attribute in the default.aspx file in my Visual Studio project was certainly set to ~masterurl/custom.master, yet the deployed file in the associated SITETEMPLATES folder used the standard ~masterurl/default.master.

Turns out that I had missed an attribute from the node in the node within ONET.XML. What I had initially was
     Url="default.aspx" NavBarHome="true">
but what I needed was
     Url="default.aspx" Name="default.aspx" NavBarHome="true">

Yet the feature deployed, and the site was created. Could perhaps do with some "fail fast" philosophy in the implementation of some of these out-of-the-box operations rather than letting default values kick-in when there is a missing configuration value?

Tuesday, May 6, 2008

Override the Edit Form SaveButton - Part 1

An overview of how to override the action of the Save Button in a SharePoint form for a specific document library (in this case a Wiki library). The intention of this brief series of articles is to record how to add a custom behaviour to the Save button of a wiki edit form.

The elements in this solution can be all included in a single Visual Studio solution, but I suggest that they are compiled into several separate SharePoint features for ease of management/deployment. All the features can be referenced in a single Manifest.xml file.

1. Create a content type feature to define a custom content type for the document library. In the XmlDocument section of the ContentType definition, specify the name of a custom template for the edit form template:


<XmlDocuments>
<XmlDocument NamespaceURI="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<FormTemplates xmlns="http://schemas.microsoft.com/sharepoint/v3/contenttype/forms">
<Display>DocumentLibraryForm</Display>
<Edit>MyCustomWikiEditForm</Edit>
<New>WikiEditForm</New>
</FormTemplates>
</XmlDocument>
</XmlDocuments>

The result of this will be that any library using this content type will display the custom content (to be created in later steps) on the edit form.

2. Create a user control file containing a new RenderingTemplate with the
template custom ID matching that in the custom content type.

To achieve this, create the new ascx file in the Visual Studio solution (as an example, I'll name it MyCustomWikiEditForm.ascx). Copy the Assembly and Register tags from the top of DefaultTemplates.ascx (located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES).

Then find (in DefaultTemplates.ascx) the RenderingTemplate node for the template being replaced, and copy/paste this into the new ascx file - in this case, I would copy the complete RenderingTemplate with ID of WikiEditForm into my new ascx file. Rename the ID of the RenderingTemplate to match the custom ID from step 1 (i.e. to MyCustomWikiEditForm).

This new ASCX file will need to be deployed to the CONTROLTEMPLATES folder by stating the destination folder in a TemplateFiles node in the Manifest.xml for the solution, as in the following example snippet:

<TemplateFiles>
<TemplateFile Location="CONTROLTEMPLATES\MyCustomWikiEditForm.ascx" />
</TemplateFiles>

In the next installment, I'll look at modifying the edit template to include a custom save button.