Showing posts with label features. Show all posts
Showing posts with label features. Show all posts

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.

Thursday, October 18, 2007

Checkin Page Shows Error For Document Library

Have been very busy creating lots of solutions to define a raft of lists and document libraries. One technique I have experimented with is as follows:
  • Manually define the site containing the lists
  • Use the SharePoint Solution Generator to create schemas for the lists
  • Run my own tool across these schemas to generate site column and content type definitions. The tool also removes some of the invlaid attributes in the schema field definitions that are created by the solution generator (I'll publish the tool here sometime soon)
  • Create solutions and features in Visual Studio using these XML definitions.
This has been saving me lots of manual effort in creating all the necessary XML. My reason for not using the VSeWSS projects for list definitions is I prefer control over the feature and manifest files, so that I can add other elements where necessary.

I came across an issue with a document library created using one of the custom list definitions. Everything seemd to work in the document library except for checking in a document - the checkin.aspx page simply displayed an error stating

"Value does not fall within the expected range"

Don't ya love that one!! Lots of investigation uncovered the cause - a malformed content type. The document library used one custom content type, and one of the field elements in the field section of the document library schema.xml file had a mispelt name attribute. Amazing that I could still add a document, and could edit the metadata values!

Tuesday, May 29, 2007

Simple script to Remove and Redeploy a Feature

This script deactivates and deletes an existing feature, then redeploys this feature - it is useful when modifying features during development:


REM Add the 12 Hive bin folder to the path for access to STSADM
@set PATH=C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN;%PATH%

REM Configure local values
set siteURL=[site URL here]
set featureName=[Name of the feature]
set WSP=[Name of the WSP file, including the WSP extension]

REM Go to the folder containing the WSP file
cd [Full path to the folder holding the WSP file]

REM Remove the solution
stsadm -o deactivatefeature -name %featureName% -url %siteURL% -force
stsadm -o retractsolution -name %WSP% -immediate
stsadm -o execadmsvcjobs
stsadm -o deletesolution -name %WSP% -override
stsadm -o execadmsvcjobs

REM Add the solution
stsadm -o addsolution -filename %WSP%
stsadm -o execadmsvcjobs
stsadm -o deploysolution -name %WSP% -immediate -allowgacdeployment
stsadm -o execadmsvcjobs
stsadm -o activatefeature -name %featureName% -url %siteURL% -force

Tuesday, May 8, 2007

SharePoint ListTemplate IDs

Here are the SharePoint 2007 ListTemplateIDs for use in event receivers (amongst others!):
List Template IDList Type
100Generic (custom) List
101Document Library
102Survey
103Links List
104Announcements
105Contacts
106Events
107Tasks
108Discussion Board
109Picture Library
110Data Source
111Site Template Gallery
113Web Part Gallery
114List Template Gallery
115Form Library
119Wiki Page Library
120Generic (custom) List in Datasheet view
150Project Tasks
200Meeting Series List
201Meeting Agenda List
202Meeting Attendees List
204Meeting Decision List
207Meeting Objectives List
211Meeting Things to Bring List
212Meeting Workspace Pages List
300Portal Sites List
1100Issue Tracking

Tuesday, February 6, 2007

Saving and Deploying a Custom Content Type

If a SharePoint 2007 site includes site columns and a content type, saving that site as a site template and then creating a new site using that template does not recreate the content type.

Therefore it seems that the site columns and content type must be deployed as a feature. Luckily Mark Collins at Share This Point has written a great guide to using features for site columns and content types.