Wednesday, September 22, 2010

Share Point 2010: Create a custom site definition Template (Topic Site Template)

This developer note will teach you the basics of building a “Topic Site – Level” template (Custom Site Template) using Visual Studio 2010

Getting Started:

Start by running Visual Studio 2010 (I’ll call it “VS-2010” from now on) and select New Project from start screen. (Figure: VS Welcome Screen)

Figure: VS Welcome Screen

Create new “Topic Site - Level” template project (Custom Site Template).

To create custom site template, we need to create a new “Site Definition” project using Visual Studio 2010.

You can create custom site template using Visual Basic or Visual C#. For now, Select Visual C# on the left, then pick "Site Definition" project under the category named “Sharepoint” then “2010”. Name your new project "TopicSiteLevelDemo" and click OK. (Figure: Create New Site Definition project)

Figure: Create New Site Definition project

“Sharepoint Customization Wizard” window opens, specify the site URL and security level for debugging

(Ex: http://usg:1909/). Click on “Validate” button for site URL validation and then “Finish”. (Figure: SharePoint Customization Wizard)

Figure: SharePoint Customization Wizard

On the right-hand side is the Solution Explorer showing all the files and folders in your application. The big window in the middle is where you edit your code and spend most of your time. Visual Studio used a default template for the Site Definition project you just created, so you have a working application right now without doing anything! This is a simple " TopicSiteLevelDemo!” project, and it is a good place to start for our application. (Figure: Default template for the Site Definition File)

Figure: Default template for the Site Definition File

Out of the box this default template gives you three files; “Onet.xml”, “webtemp.xml” and “default.aspx” files.

Let me explain each files in brief which relevant to the “Topic Site Level - 1” template.

Onet.xml File

In an Onet.xml file, the Feature element is used within a site definition configuration to contain a reference to a Feature instance and default property values. The Configuration element specifies lists and modules to use when creating SharePoint sites. For information about the format and elements used in site definitions.

SharePoint Foundation activates Features specified within the Onet.xml file in the order that they are listed. Consequently, you must specify Features that are depended upon before Features that depend upon them.

The default “onet.xml” file uses the default “V4.master” file, for the site definition’s master page.

For “Infor Sales Portal Topic site levels”, used custom master page named, “infor_V4.master”.

This defined it “onet.xml” file under the tags named, “” and “(Figure: Code sample for custom mater page defining)

Figure: Code sample for custom mater page defining

Configurations Element

Each configuration element in the configurations section specifies the lists, modules, and Features that are created by default when the site definition configuration or Web template is instantiated.

ListTemplates Element

The ListTemplate section specifies the list definitions that are part of the “Topic Site” template. Each ListTemplate element specifies an internal name that identifies the list definition and also specifies the display name for the list definition. Example: “Topic Site Announcements”

Each List element specifies the title of the list definition and the URL for where to create the list. (Figure: ListTemplate element of “TopicS ite – Level 1” onet.xml)

Figure: ListTemplate element of “TopicSite – Level 1” onet.xml

SiteFeatures Element

The “SiteFeature” element contains references to site to site collection and site – scoped features to include in the site definition.

WebFeatures Element

The “WebFeature” element contains references to site to site collection and site – scoped features to include in the site definition.

Modules Element

The Modules collection specifies a pool of modules. Any module in the pool can be referenced by a configuration if the module should be included in Web sites that are created from the configuration. Each Module element in turn specifies one or more files to include, often for Web Parts, which are cached in memory on the front-end Web server along with the schema files. You can use the Url attribute of the Module element to provision a folder as part of the site definition. This markup is supported only for backward compatibility. New modules should be incorporated into Features. (Figure: Module element of “TopicSite – Level 1” onet.xml)

Figure: Module element of “TopicSite – Level 1” onet.xml

Getting SharePoint in-buit list web part references in onto the “InforSalesPortal” Home Page; (Figure: element of “TopicSite – Level 1” onet.xml)

Figure: element of “TopicSite – Level 1” onet.xml

Web* Temp.xml File

Example: “webtemp_TopicSiteLevel1.xml”

Each server in a deployment of Microsoft SharePoint Foundation has at least the originally installed WebTemp.xml file located in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\LCID\XML folder, where LCID is the numeric ID of the language/culture, such as 1033 for English. There may also be one or more custom WebTemp*.xml files. The WebTemp*.xml files contain an itemization of the site definition configurations that are available in the UI for users to select when creating a new Web site. The UI varies depending on whether the Silverlight or HTML site creation page is being used.

The Template element specifies the site definitions that are being made available in the WebTemp*.xml file. Each site definition is defined with a Template element. Each site definition has one or more site definition configurations that can be used to instantiate sites. Each Template element specifies a unique ID and a name that corresponds to a site definition subfolder within the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates folder. (Example: “%ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates\TopicSiteLevel1”)

A Template element can contain any number of Configuration child elements. Each such child represents a site definition configuration.

The ID attribute of each Configuration element corresponds to the ID of another Configuration element that is in an Onet.xml file. The second Configuration element specifies the lists and modules of the site definition configuration.

Each Configuration element in a WebTemp*.xml file also specifies the title and description (and the path to the image) of the configuration that is displayed in the SharePoint Foundation UI when a user is creating a new site. A configuration can be hidden from the user interface (UI) by setting its Hidden attribute to TRUE.

The DisplayCategory attribute of a Configuration element in a WebTemp*.xml specifies the category of site type that the site appears under in the UI; for example, "Infor" (Figure: “webtemp_TopicSiteLevel1.xml” file of “Topic Site – Level 1” template)

Figure: “webtemp_TopicSiteLevel1.xml” file of “Topic Site – Level 1” template

default.aspx file

This is the Topic Site template home or content area and layout of the Site Definition.(Figure: default.aspx file)

Figure: default.aspx file