Raghu's SharePoint Corner: ItemTemplate

My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
http://www.sharepointcolumn.com
and update your bookmarks.

Showing posts with label ItemTemplate. Show all posts
Showing posts with label ItemTemplate. Show all posts

May 7, 2009

Template MetaData Files .VSTemplate extensions

To start with VSTemplate, lets first know where are VSTemplate files used.These files are used to create custom ItemTemplate and custom ProjectTemplate.Once these templates are created you can make it appear in the New New Item and the New Project dialog boxes.

1. ItemTemplates: All the templates that appear in the Add New Item Dialog Box are called Item Templates

2. ProjectTemplates: All the templates that appear in the Create/Add New Project Dialog Boxare called Project Templates

Before getting into creation of custom ItemTemplates, lets understand the structure of .VSTemplate which is the core part of Item and Project Templates

The .vstemplate file for project templates consists of three fundamental elements:

1. VSTemplate:  Identifies the template as a project or item template and provides the template version number. The attribute Type for VSTemplate specifies weather its project template or a Item Template

2. TemplateData: Categorizes the project template and defines   display characteristics for the New Project or Add New Item dialog box.It defines the name of the   tempalte,the description of what the template does, its default name and many other attritbute which we will  look into when we create a custom item template in the comnig posts





3. TemplateContent:Specifies the files included in the template.This part of the templates specifes what are the assembly references to be included, what are the default files need to be created when a new item is created usings this template





Apart from the above three fundamental there are other 2 optional sections, which may be needed during creation of custom templates

4. WizardExtension:This custom wizard helps to define additional custom functionality to the custom item templates, like adding the receiver class and the Recevice assembly into the feature dynamically


5. WizardData: This section of the VSTempalte helps us to pass custom xml to the custom wizard extension





Sample VSTemplate structure is shown below


<VSTemplate Version="2.0.0" Type="Item" 
xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>Timer Job</Name>
<Description>Add a new timer job</Description>
<ProjectType>CSharp</ProjectType>
<TemplateID>TimerJob</TemplateID>
<ShowByDefault>true</ShowByDefault>
<DefaultName>TimerJob</DefaultName>
<Icon>Icon.ico</Icon>
</TemplateData>
<TemplateContent>
<References>
<Reference>
<Assembly>
System.Web, Version=2.0.0.0, Culture=neutral,
 PublicKeyToken=b03f5f7f11d50a3a
       </Assembly>
</Reference>
<Reference>
<Assembly>Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral,
 PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL</Assembly>
</Reference>
</References>
<Folder Name="FolderName">
<ProjectItem SubType="Code" 
TargetFileName="feature.xml"
 ReplaceParameters="true">..\feature.xml</ProjectItem>
             <ProjectItem SubType="Code" 
TargetFileName="$rootname$.cs"
 ReplaceParameters="true">..\Job.cs</ProjectItem>
<ProjectItem SubType="Code" 
TargetFileName="$rootname$Installer.cs"
 ReplaceParameters="true">..\JobInstaller.cs</ProjectItem>
</Folder>
</TemplateContent>
<WizardExtension>
<Assembly>Wiz.CustomWizard, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=d24561bc194c5ab4, Custom=null</Assembly>
<FullClassName>Wiz.CustomWizard.CustWizard</FullClassName>
</WizardExtension>
</VSTemplate>

May 5, 2009

Custom template parameter name for Item Templates

Recently i thought of creating a ItemTemplates so that the dev effort during the development reduces drastically if someone is new to the project or the technology. A new developer just need to create a new item using the custom item templates.

Before getting into the deep on how to create custom item templates for visual studio. Please go through the list of reserverd template parameter names, whic will help developer to understand the naming conventions used for item templates.

All the template parameters are case sensitive
Reserved Template Parameters
The following table lists the reserved template parameters that can be used by any template.

1. clrversion
Current version of the common language runtime (CLR).
2. GUID [1-10]
A GUID used to replace the project GUID in a project file.
You can specify up to 10 unique GUIDs (for example, guid1).
3. itemname
The name provided by the user in the Add New Item dialog box.
4. machinename
The current computer name (for example, Computer01).
5. projectname
The name provided by the user in the New Project dialog box.
6. registeredorganization
The registry key value from HKLM\Software\Microsoft
\Windows NT\CurrentVersion\RegisteredOrganization.
7. rootnamespace
The root namespace of the current project. This parameter is
used to replace the namespace in an item being added to a project.
8. safeitemname
The name provided by the user in the Add New Item dialog box,
with all unsafe characters and spaces removed.
9. safeprojectname
The name provided by the user in the New Project dialog box,
with all unsafe characters and spaces removed.
10. time
The current time in the format DD/MM/YYYY 00:00:00.
11. userdomain
The current user domain.
12. username
The current user name.
13. year
The current year in the format YYYY.