Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Add a custom template to Visual Studio .NET 2003

0.00/5 (No votes)
28 May 2004 1  
An article that explains a method to add your own custom template in the Visual Studio .NET 2003 IDE.

Sample Image

Introduction

I have always wondered if there is a way to change or rather remove the default contents of the 'New Item' presented by VS.NET 2003 IDE, when I create a new file for my Microsoft .NET project. I knew that it should be somehow possible to do it, but will it take me to install a new plug-in or make more of Google to do it.

I tried to check some sources for this purpose and resulted myself in experimenting with the information in the Visual Studio .NET 2003 Help Documentation. All the information given here are from my understanding on the information present in the Visual Studio .NET 2003 Help Documentation.

Note: the attached files are just sample files and are not source files as you may find in other articles.

Background for the article

This article's contents are written after I went through the contents in Visual Studio .NET 2003 Help Documentation.

Template Creation Process

As an ASP.NET developer, for this article, I would be focusing on the template for 'WebForm' using Visual Basic .NET.

I hereby assume that the visitor to this article would have a good idea on how to create and use a Project using Visual Basic .NET in Visual Studio .NET 2003 IDE. You can create a new WebForm for your web project from the Visual Studio .NET 2003 by:

File --> Add --> Add New Item (select the �WebForm� there)

The default 'aspx' page generated by Visual Studio .NET 2003 would be as follows:

<%@ Page Language="vb" AutoEventWireup="false" 
    Codebehind="WebForm2.aspx.vb" Inherits="TestWeb.WebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
  <head>
    <title>WebForm2</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
    <meta name=vs_defaultClientScript content="JavaScript">
    <meta name=vs_targetSchema 
        content="http://schemas.microsoft.com/intellisense/ie5">
  </head>
  <body MS_POSITIONING="GridLayout">

    <form id="Form1" method="post" runat="server">

    </form>
  </body>
</html>

I wanted the above code to be generated as follows:

<%@ Page Language="vb" AutoEventWireup="false" 
  Codebehind="TemplateWebForm2.aspx.vb" Inherits="TestWeb.TemplateWebForm2"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>My Template</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
        <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" 
            content="http://schemas.microsoft.com/intellisense/ie5">
        <meta name="Author" content="Saravana Kumar S P">
        <meta name="Author Mail" content="kumarsps@hotmail.com">
        <!--
    All sorts of stuffs that I want to put here
    -->
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
        </form>
    </body>
</HTML>

There are two ways to play around with this.

  1. Replace the template - change the default content of the WebForm from Visual Studio .NET 2003�s content to the required format.
  2. Create a new template - create with the different content for the WebForm, and allow it to be selected from the screen, when creating a �New Item�.

We will see both of them in this article. Although I am most interested in the second option.

Option 1: Replace the template.

This is as good as a piece of a cake.

  1. Open the following directory:
    C:\Program Files\Microsoft Visual Studio .NET 2003\
                Vb7\VBWizards\WebForm\Templates\1033
  2. The above folder is self explanatory. It is in the Visual Studio .NET 2003 installation folder, and I have chosen the WebForm in the VBWizards, that is in the VB language folder for VS .NET 2003. In this folder, we have one file WebForm.aspx.
  3. This is the template file we are talking about. Now, open the file and modify the contents and save it back.
  4. Yes, we got the job done.
  5. Now, open a Web Project in VB.NET, in your Visual Studio .NET 2003 IDE.
  6. Create a new WebForm for the project. Here, you will get the contents from the file you had just edited.

Option 2: Create a new template.

Note: sample files in this article correspond to this method.

This is something I was looking for days, and oops, finally got it from the Visual Studio .NET 2003 Help Documentation. To do this, close the Visual Studio .NET 2003 IDE and follow these steps in the given order:

  1. Locate the following folder:
    C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards
  2. Copy the folder WebForm into a new name as TemplateWebForm.
  3. Now locate this new path:
    C:\Program Files\Microsoft Visual Studio .NET 2003\
               Vb7\VBWizards\TemplateWebForm\Templates\1033
  4. Rename the file WebForm.aspx to TemplateWebForm.aspx.
  5. This file is going to be the new template. So, change the contents of this file TemplateWebForm.aspx. You can come back and change the contents later too.
  6. Locate the file default.js in one of the new folders created just now:
    C:\Program Files\Microsoft Visual Studio .NET 2003\
                Vb7\VBWizards\TemplateWebForm\Scripts\1033
  7. In line #16, change the �WebForm.aspx� to �TemplateWebForm.aspx�.
  8. Save and close the file, you may not need to edit this file anymore.
  9. Now go to this folder:
    C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBProjectItems
  10. Copy the file WebForm.vsz as a new file and name it as TemplateWebForm.vsz.
  11. In line #3, change the WebForm to TemplateWebForm.
  12. Save and close the file.
  13. Go in to the directory Web Project Items and create a new file and name it as UserProjectItems.vsdir (you will have to maintain the extension of the file as it is given above).
  14. Put the following line of code there:
    ..\TemplateWebForm.vsz|{FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|
      My Template|10|A user-created web form for CP|
      {FAE04EC1-301F-11d3-BF4B-00C04F79EFBC}|4534|0|TemplateWebForm.aspx
  15. Now, fire up the Visual Studio .NET 2003 IDE, and open / create your web project.
  16. Add a NEW ITEM, and the link for the template is listed there as �My Template�.
  17. Select it and play around with it.

To Do�s for this article:

  1. The template is listed in the top level root of �Web Project Items� only. This can also be made available in the respective folders also � �UI� in this case.
  2. Show the �Add My Template� in the menu �Add�, that appears when you right click the Web Project in the Solution explorer.

History

To be updated whenever I find that I have something new to be told about this article!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here