Skip to main content

Cloud

Attach custom forms to a Content Type: Part 1

My wife owns baskets; many baskets: baskets of every size and shape for every imaginable purpose. The purpose of some is purely decorative, but others serve much more pragmatic purposes: a variety of small ones to hold jelly, candy, or candle jars; a large flat one to dump the mail and other unsorted pamphlets and papers, one to hold coins, another to hold knick knacks, four on the pantry hold sugar, flour, coffee beans, and some other unknown white substance; small ones for holding recipes and others for index cards, although I have no idea what the difference is. They adorn the cabinets, shelves, tables; every nook and cranny in the house: there is even a 55 gallon plastic trunk filled with baskets.

In SharePoint, our baskets are content types. Content Types hold a variety of functionality, and like my wife’s baskets, can come in many shapes and sizes; and serve many purposes. Recently, I was reminded how content types can hold custom new and edit forms such that the user will get the customized form when adding an item to a list that uses said content type. This reminder prompted me to formulate a four part series to cover the topic of adding such custom forms to a content type.

Project Setup and Content Type Feature

In this part of the series, I will walk through the procedure for creating a Visual Studio project and the content type that will act as the "basket" for our custom forms. Although, I have recently started using the Visual Studio Extensions for WSS 1.2, I will do things the manual way in this series so that we may look at the nuts and bolts of things: So that although you merely wish to know the time, I will tell you how to build the watch.

The content type that I will create is one that will be useful for tracking character sheets for the world’s most popular role-playing game (as opposed to the world’s best role-playing game or the world’s coolest role-playing game). The goal is to include a new and edit form that can be styled to look like the character sheet used in the game rather than the default SharePoint table view of the fields.

Setup the Visual Studio Project

Begin by creating a Visual Studio Class project. Once open, you may either delete the class1.cs file or rename it to one of the form’s code behind classes. Next create the TEMPLATE directory and the necessary subfolders to implement the content type as a feature in SharePoint. At this point, I usually add the xml and aspx files to the appropriate folders, as well as the class files, but I have not yet added any code to them.

Create the Feature

After creating the framework for the content type feature, start by creating the feature definition in the Feature.xml file. The ID value is a guid that has been stripped of the curly braces. The other information in the Feature file describes the information that will appear in the Site Settings area of the target SharePoint site. The Scope determines where in Site Settings you will find the feature; Web scope are located in the Web features section, Site scope are located in the Site Collection features section, and Farm scope are located in Central Admin. Finally, the ElementManifest points to the xml file that defines the content type and site columns.

Create Content Type

Creating the content type is a straight forward process with the exception of the ID field which I have written about in a previous post. In this example, I am creating the custom site columns in the same xml file as the content type. In that past, I have implemented custom site columns in their own features. Regardless of the approach, the content type FieldRefs section needs the IDs and names of any site columns that it will use.

One interesting this that I am doing with this content type is to rename the built-in Title site column. This is the field in the list that usually has the hyperlink to the details page. In this case, I want to use the Title field but I want it to show the caption "character name" rather than the caption of "title." Therefore, I add the Title FieldRef and add the DisplayName attribute.

In Part II

In the next article, I will discuss how to create the custom pages that we are including in our content type.

EndNote

Recently, Safari Bookshelf added Scott Hillier’s WSS and MOSS Development video to their library. After watching this series, I modified my implementation of this technique to match Scott Hillier’s technique. I highly recommend this video for two reasons; first it offers a more in depth analysis of this topic and is on video; second, the series comes with some utilities and shortcuts that are more than worth the price of the videos.

More detail on adding custom information to content types is also available at the MSDN library. This section of the MSDN library provides detailed technical information about the FormTemplates and FormUrls sections utilized in the content type definition.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

PointBridge Blogs

More from this Author

Follow Us