Click here to Skip to main content
12,949,083 members (58,140 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 6 Mar 2006

Quick Open Add-in for Visual Studio

, 6 Mar 2006 CPOL
Rate this:
Please Sign up or sign in to vote.
Step-by-step creation of a quick open add-in for Visual Studio 2005


While working on a project, I don't like to use the mouse very often. But some tasks like opening a project file in Visual Studio need to use the mouse. So I decided to implement an add-in that doesn't need any mouse strokes (but is optional) and assigns a shortcut "Ctrl+Shift+Alt+N". Here is my quick open add-in and step by step instruction on how to write such an add-in for Visual Studio .NET 2005.

Using the Code

First of all, you should create a new Visual Studio .NET 2005 add-in project. File » New » Project. Select Other Project Types » Extensibility »Visual Studio Add-in from New Project dialog. Give a name to the project like QuickOpen and click OK.

On Add-in wizard, select Create an add-in using Visual C# option, Microsoft Visual Studio 2005 as application host, type a name and description and the wizard will generate your add-in project.

After your Add-in project is created, Visual Studio opens the Connect class to edit. Now we should create a named command so we can create a menuItem to allow users to interact with our add-in.

Command command =
                                  "Quick way to open files ",
                                  ref contextGUIDS,

You have your command and now you can add your command to open menu placed under the Main menu:

CommandBarPopup filePopup = (CommandBarPopup)menuBarCommandBar.Controls["File"];
CommandBarPopup openPopup = (CommandBarPopup)filePopup.Controls["Open"];
command.AddControl(openPopup.CommandBar, 4);

Now we have successfully added our menu item under File » Open with the index 4.

When the user clicks Quick Open menu item, Visual Studio will call the Exec function that comes with the IDTCommandTarget interface. Note that, since you may have more than one command in your add-in, Visual Studio will call that method with the CmdName parameter that's the name of the command being called. We can optionally add keybindings for addin as follows :

command.Bindings = "Global::Ctrl+Shift+Alt+N";

Here, Global indicates that the shortcut can be used anywhere within Visual Studio.

We've almost finished our add-in. What we have to do is to analyze our solution and display the list of files. You can enumerate DTE2.Solution.Projects and then ProjectItems of each project. If you also want to display pretty icons that inform the user about the type of file, you can find each ProjectItem's type with its Kind property. Kind property gives you a GUID string, so you should know which GUID belongs to which type (or you may use Constants class for common types).

FileCodeModel fileCodeModel = applicationObject.ActiveDocument.ProjectItem.FileCodeModel;
foreach (CodeElement codeElement in fileCodeModel.CodeElements) {
   //Add codeElement to your list

private void AddChilds(int parentId,CodeElements codeElements) {
   foreach (CodeElement codeElement in codeElements) {
    if (codeElement.Kind != vsCMElement.vsCMElementParameter &&
        codeElement.Kind != vsCMElement.vsCMElementOther) {
     //Add codeElement to your list

What we have done till now is, we have placed our menu item and analyzed our solution, finally we have listed the solution files. When the user selects one of the listed files, you should check whether it is a physical file (its Kind should be Constants.vsProjectItemKindPhysicalFile)

Finally, we can open our file in Visual Studio with the following code:


I've used icons that ship with Visual Studio .NET 2005, placed under C:\Program Files\Microsoft Visual Studio 8\Common7\VS2005ImageLibrary\ I could not find any license terms for them. If any exist, please let me know.


  • 6th March, 2006: Initial post


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


About the Author

Web Developer
Turkey Turkey
He is a Computer Engineer living in İzmir,Turkey; worked on desktop applications, web technologies, smart clients with various programming languages like, php, C#, Java and with various database managements systems like Mysql, MsSql and Oracle

You can find his other posts and articles on his blog at , you can also find his other open source projects on his web site

You may also be interested in...

Comments and Discussions

GeneralQuick open file for VS 2008 Pin
Jhimy Fernandes Villar21-Oct-09 14:03
memberJhimy Fernandes Villar21-Oct-09 14:03 
GeneralKeep up the good work and an off-topic add-in question please Pin
Alexandru Matei4-Dec-06 9:48
memberAlexandru Matei4-Dec-06 9:48 
GeneralRe: Keep up the good work and an off-topic add-in question please Pin
stmarti10-Jan-07 2:21
memberstmarti10-Jan-07 2:21 
GeneralRe: Keep up the good work and an off-topic add-in question please Pin
Alexandru Matei10-Jan-07 5:56
memberAlexandru Matei10-Jan-07 5:56 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170524.1 | Last Updated 6 Mar 2006
Article Copyright 2006 by fatihboy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid