CodeSnippets in VS 2005

Valued Contributor
Valued Contributor

In VS 2005 there is a new feature called CodeSnippets. These are xml files containing often used code that can be saved in the MySnippets folder and then appear in Intellisense (standard path: C:\Documents and Settings\[UserName]\My Documents\Visual Studio 2005\Code Snippets\[Programming Language]\My Code Snippets). From Intellisense, hitting tab twice will insert the code and any variable names etc can be navigated with the tab key.

 

I have attached a C# example for getting a Solid Edge doc (it appears as GetSEDoc in intellisense).

 

I will post some more when I get a chance (in VB and C#)

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 8/9/2006 3:16:29 AM

4 REPLIES

RE: CodeSnippets in VS 2005

Valued Contributor
Valued Contributor

OK - it seems like no one is all too interested here, but I'll give it another go.

 

I checked out the VB.Net code snippet stuff and discovered that the snippets don't appear in the normal intellisense, rather you type the start of the snippet shortcut and then a question mark then hit TAB and the snippert list appears.

e.g.

for the attached ReleaseSEObj snippet you could type rel? and hit TAB, check that the correct snippet is selected, hit return and then you've got the classic:

 

If Not(solidEdgeObject Is Nothing) Then

Marshal.ReleaseComObject(solidEdgeObject)

solidEdgeObject = Nothing

End If

 

 

then enter the name of the object variable (the first 'solidEdgeObject' is already selected) hit enter and get on with some proper coding.

 

I have attached the following snippets in VB.Net:

GetSEDoc

GetSEAttrs

ReleaseSEObj

 

the download in the last post has been updated with the same snippets for c#

 

 

Let's see if anyones interested now there's some VB examples...

 

Cheers

Calum

 

Posted by: Calum McLellan
Post date: 8/17/2006 8:45:06 AM

RE: CodeSnippets in VS 2005

Valued Contributor
Valued Contributor

Hey Jason - where's the edit function??

 

I couldn't edit the first post so here's the updated c# download

 

Posted by: Calum McLellan
Post date: 8/17/2006 8:46:58 AM

RE: CodeSnippets in VS 2005

Valued Contributor
Valued Contributor

Calum,

 

Edit should show up if you're logged in and the OP. If it doesn't, I don't know why.

 

Can you fill us lazy people in on how to use \ create snippets? Where do we put these files and how do we create our own?

 

 

Posted by: Jason Newell
Post date: 8/21/2006 2:47:06 AM

RE: CodeSnippets in VS 2005

Valued Contributor
Valued Contributor

Hi Jason,

 

You can put these files anywhere you want so long as you add the folder in the "Code Snippets Manager" in the Tools menu in VS 2005.

The files are in xml format. I'll post an overview of the sections as soon as I get a bit of time (hopefully tomorrow), but if you open the files in VS it should be reasonably straight foward to figure out what's going on.

The use of code snippets in code is detailed in my last post, let me know if this isn't clear enough.

 

Cheers

Calum

 

P.S. - the edit functions back - I was logged in before, but I guess the server was having a bad day.

 

Posted by: Calum McLellan
Post date: 8/21/2006 10:04:23 PM