Click here to Skip to main content
15,878,959 members
Articles / Web Development / ASP.NET
Article

Add a custom template to Visual Studio .NET 2003

Rate me:
Please Sign up or sign in to vote.
4.70/5 (13 votes)
28 May 20044 min read 114.4K   449   39   14
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:

ASP.NET
<%@ 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:

ASP.NET
<%@ 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


Written By
Team Leader Emirates Group IT (Emirates Airline)
United Arab Emirates United Arab Emirates
Saravana Kumar lives in the commercial hub of Dubai.

He started programming when he was 14 with FORTRAN in the DOS based PCs. He developed himself with the evolution of Windows 3.1, 95, 98, 2000, XP, Vista... along with the programming languages and tools like C, BASIC, C++, JAVA, DBASE 3+ etc.

He completed his Engineering Graduation in Computer Science in the year 2000 and started his career into software by programming into the microprocessor. C, DSP were his stepping stone as a Software Programmer, in Madras, India.

He changed career by taking a big leap in switching himself (also relocating to Dubai, UAE) to Web Sites and stuffs. He was playing with HTML, ASP, and Java Script for a while.

He got himself a break in his career for a few months and got a dip into the .NET. He then became a .NET programmer (basically into ASP.NET) in Dubai Technologies, Dubai, UAE. Then circumstances forced him to take a break and came back to Dubai. He is working as a Software engineer. He enjoys his work, right now, fully occupied, but still finds time to spare at the Code Project.

He enjoys playing games like solitaire, commandos. He likes music a lot. He loves to be alone most of the time (as a Piscean - a day dreamer). He is happy that he is the first person in his family to 'work' than involve in the business. He is sad that he is not able to keep in touch with his friends and loved ones. But in a way happy that he still remembers them.

Saravana Kumar got a new PDA (iMate PDA2k) March 2005, and spends quality time with it. Still not tired of downloading the software and not tired of the upgrades for the device.

Update: Saravana Kumar is a 'Contributing Editor' for PocketPCDubai website, writing reviews and posting news/messages relating to PocketPC.

His mobile usage increased a lot and the list is,

Nokia 3330
iMate PDA2k
HP iPAQ HW 6515
AXIA A108
Everex ETEN G500
iMate PDA-n
(more to come...)

Comments and Discussions

 
GeneralRe: Great!, and also Pin
Jeremy Rosenberg30-Sep-04 9:56
Jeremy Rosenberg30-Sep-04 9:56 
GeneralRe: Great!, and also Pin
Ashley van Gerven10-Nov-04 18:00
Ashley van Gerven10-Nov-04 18:00 
GeneralGood one! Pin
Prakash Nadar30-May-04 6:20
Prakash Nadar30-May-04 6:20 
GeneralRe: Good one! Pin
Sarvesvara (BVKS) Dasa2-Jun-04 4:23
Sarvesvara (BVKS) Dasa2-Jun-04 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.