Click here to Skip to main content
15,305,508 members
Articles / Visual Studio
Technical Blog
Posted 9 May 2014

Tagged as


2 bookmarked

Got Sweet Code? Save It!

Rate me:
Please Sign up or sign in to vote.
4.33/5 (2 votes)
12 May 2014CPOL2 min read
Got sweet code? Save it!

If you’re a Visual Studio user, you’re more than familiar with snippets (I would hope). ctor, propa, testm, all very useful. But have you created your own snippets?

You can do this with tools like the Snippet Designer extension, or roll your own by creating & editing a snippet XML file by hand based on the snippet schema.

Ain’t nobody got time for that.

Far and away, the quickest way I’ve found to save code I reuse often is even simpler than all that. And I’m about to clue you in on it.

If you’ve been to BUILD or other conferences/presentations by Microsoft folk, you’ve undoubtedly seen them take their “sample code” and insert it via a snippet. But what I saw at BUILD 2014 this past April surprised me. All the presenters had the toolbox open *in code view* and were simply dragging & dropping code snippets from the toolbox right in to their code window. Every time they did it, they did so fast that I wasn’t even able to see exactly where things were coming from or what they looked like.

This past week I was preparing for a presentation and decided to just give something a whirl:

Image 1

I got my code all ready in my sample app, and highlighted it. Then I got an idea… what if…

Image 2

Sure enough, just dragging the code over to the toolbox gives you a little ‘text’ entry in your toolbox. You can even rename it so you know what you’re going to use it for:

Image 3

Now, when you want to use it again, you just drag that toolbox item back in to your code:

Image 4

And boom, it appears.

Insanely useful for doing live-code presentations, or storing away snippets you use over and over without the hassle of actually writing a snippet.

The best part? These items persist across VS launches; they’ll be there the next time you launch Visual Studio.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer (Senior)
United States United States
I'm a Sr. Software Engineer in the Seattle area primarily focused on serverless technologies in the cloud. In my free time I enjoy hiking & other adventures with my family around the Puget Sound and the country! You can find out more about me at my homepage:

Comments and Discussions

SuggestionShare its tools within a developer team Pin
Pascal-7812-May-14 20:26
professionalPascal-7812-May-14 20:26 
QuestionImages not showing! Pin
Carlos190712-May-14 0:44
professionalCarlos190712-May-14 0:44 
AnswerRe: Images not showing! Pin
BC3Tech12-May-14 9:49
MemberBC3Tech12-May-14 9:49 
Thanks for alerting me, Carlos. The codeProject editors go through my posts when they're consumed and make the necessary changes and apparently haven't fully vetted this one. I'll alert them to it.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.