Add Your Own HTML template to the "Add New Items"
list in VS.NET by Curtis Swartzentruber
If you are like me, you tend to just jump into the Visual Studio IDE and get to work. However, there is a lot of customization you can do to improve your productivity. For example, large project teams can use Enterprise Templates to enforce coding standards, layouts, and guidelines across a project or organization.
I just wanted to do something simple though. When you are working in Visual Studio, you can use the "Add New Item" functionality to add a file of a certain type to your project, such as a blank HTML page, aspx page, or vb class file. No big news there. When adding an HTML page, I wanted the option of using my own template rather than the default. There are basically 2 ways to do this, change the default template VS.NET uses or create your own template.
The templates that VS.NET uses for VB.NET are located in your "Microsoft Visual Studio.NET" directory, typically in "Program Files." on whatever drive you installed VS.NET on. Go to:
{x]:Program FilesMicrosoft Visual Studio.NETVb7VBWizardsHTMLPageTemplates1033HTMLPage.htm
and just change that to include whatever you want. Obviously you can do this with the other templates in that directory as well. I'm just focusing on the HTML template.
To add an additional template, here are the steps I used (please change HTMLExamplePage to whatever you like):
- Copy the "HTMLPage" directory (as listed above) to an "HTMLExamplePage" directory in the same folder.
- This directory should have 2 subdirectories. One called "Templates" and one called "Scripts."
- Rename the template file in the copied "HTMLExamplePageTemplates1033" directory to "HTMLExamplePage.htm" or whatever you want. I don't think you necessarily have to change the name of the template file, although it probably makes the most sense. Edit the file to include whatever HTML you want your template to have.
- Move to the "Scripts1033" subdirectory and there will be a "default.js" javascript file.
- Edit this file. On line 11, change "HTMLPage.htm" to whatever you called your template file
- Now we need to move up to the "Vb7VbProjectItems" directory (in Microsoft Visual Studio.NET).
- File copy "HTMLPage.vsz" to "HTMLExamplePage.vsz." Edit the file by changing "Param="WIZARD_NAME= HTMLPage" to "Param="WIZARD_NAME = HTMLExamplePage"
- Still in the "VbProjectItems" directory, go to the "Web Project Items" subdirectory.
- Open the "WebProjectItems.vsdir" file (Notepad or VS.NET will open it).
- This file tells VS.NET how to show all the "Add New Item" items. Scan down through the file to the following line:
..HTMLPage.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}| #3070 |70|#3071|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4537| |HTMLPage.htm
- Duplicate this entry in the WebProjectItems.vsdir file (I just copied it right below the original).
- Change it to reference your new template.
..HTMLExamplePage.vsz|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|Example Page|70|#3071|{164B10B9-B200-11D0-8C61-00A0C91E29D5}|4537| |HTMLExamplePage.htm
- If you want to know more about vsz or vsdir files, please see the VS.NET help. These steps may not work with all file types, but they do work with HTML templates. I would expect they will work with aspx templates as well, although I haven't tested that yet.
- You will notice I also changed #3070 to Example Page. This entry controls what shows up in the "Add New Item" dialog box so you can differentiate your template from the normal "HTML Page" template.
- Restart VS.NET and open a Web application. When you do "Add New Item," your template should now be in the list.
You can do a whole lot of things with templates in VS.NET, although my knowledge at this point is limited. This is barely scratching the surface. However, I had to dig around a bit to figure this out, so I thought I would share this info.
|