Code Snippets in Visual Web Developer and VS 2005
 
Published: 26 Jan 2006
Unedited - Community Contributed
Abstract
In this article, Scott examines Code Snippets using Visual Web Developer and Visual Studio 2005.
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 15516/ 39

Introduction

Republished with Permission - Original Article

One of the nice new features of Visual Web Developer (which is free) and VS 2005 is the new "Code Snippet Support" that has been added.  This handy feature allows you to quickly find and use code-libraries of common patterns (examples: get/set property definitions, data access code, file IO, exception handling blocks, etc).

To try it out, just right-click within a code file to bring up a context menu:

Figure 1

 

Select "Insert Snippet" from the context menu, and then choose the category of snippet you want to use (for example: "File System"):

Figure 2

And then the code-nugget to inject:

Figure 3

You'll then have the code added at that location in the editor.  Common variable values will be automatically highlighted for you, with the cursor set on the first value.  You can replace the values with your own, and then tab to automatically jump to fill in the next value (no need to use the mouse or arrow keys):

Figure 4

What makes code snippets really cool is that you can easily create and define your own.  So over-time you can build up your own library of common patterns that you use, and add efficiency to your daily tasks (for example: do you always write data code in a certain way, or insert objects into the ASP.NET cache using a specific pattern, or validate security, etc.)  These snippets are stored within XML files on disk, and can be easily shared across a dev team (or friends).

Update: Several people have pointed out that C# doesn't have as many built-in snippets out of the box as the VB screenshots above.  You can download the same routines (but in C#) to add to VS 2005 or Visual Web Developer here to get them: http://msdn.microsoft.com/vstudio/downloads/codesnippets/default.aspx

Here are a couple of articles and links I found on the web that go into how to build and use your own snippets:

http://aspalliance.com/863

http://aspnet.4guysfromrolla.com/articles/122105-1.aspx   

http://www.developer.com/net/vb/article.php/10926_3505156_1  

http://blog.davidyack.com/archive/2006/01/26/3884.aspx (David's blog has a whole list of great links here)

http://blog.davidyack.com/archive/2006/01/27/3886.aspx  

http://aspalliance.com/752

Hope this helps,

Scott

Resources



User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-03-29 8:06:50 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search