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">
<!---->
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
</form>
</body>
</HTML>
There are two ways to play around with this.
- Replace the template - change the default content of the WebForm from Visual Studio .NET 2003�s content to the required format.
- 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.
- Open the following directory:
C:\Program Files\Microsoft Visual Studio .NET 2003\
Vb7\VBWizards\WebForm\Templates\1033
- 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.
- This is the template file we are talking about. Now, open the file and modify the contents and save it back.
- Yes, we got the job done.
- Now, open a Web Project in VB.NET, in your Visual Studio .NET 2003 IDE.
- 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:
- Locate the following folder:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBWizards
- Copy the folder WebForm into a new name as TemplateWebForm.
- Now locate this new path:
C:\Program Files\Microsoft Visual Studio .NET 2003\
Vb7\VBWizards\TemplateWebForm\Templates\1033
- Rename the file WebForm.aspx to TemplateWebForm.aspx.
- 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.
- 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
- In line #16, change the �WebForm.aspx� to �TemplateWebForm.aspx�.
- Save and close the file, you may not need to edit this file anymore.
- Now go to this folder:
C:\Program Files\Microsoft Visual Studio .NET 2003\Vb7\VBProjectItems
- Copy the file WebForm.vsz as a new file and name it as TemplateWebForm.vsz.
- In line #3, change the WebForm to TemplateWebForm.
- Save and close the file.
- 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).
- 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
- Now, fire up the Visual Studio .NET 2003 IDE, and open / create your web project.
- Add a NEW ITEM, and the link for the template is listed there as �My Template�.
- Select it and play around with it.
To Do�s for this article:
- 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.
- 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!