Code Snippets in Visual Web Developer and VS 2005
page 2 of 3
by Scott Guthrie
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 14817/ 63
Article Contents:

 

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


View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





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


©Copyright 1998-2020 ASPAlliance.com  |  Page Processed at 2020-05-31 10:58:03 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search