Click here to Skip to main content
15,394,162 members
Articles / Programming Languages / C#
Posted 10 Aug 2007


296 bookmarked

The Code Project Browser Add-in for Visual Studio 2005 and 2008

Rate me:
Please Sign up or sign in to vote.
4.90/5 (108 votes)
27 Mar 2008CPOL9 min read
An add-in for browsing, downloading and managing CodeProject samples directly in Visual Studio
Code Project Browser Addin screenshot


At SlickEdit, we've put several "advertorials" out now on The Code Project about our Tools for Visual Studio product. I'm one of the developers on the Tools team [profile], and I love The Code Project for learning how to do new things, especially because I learn best by seeing examples of how something's done. However, in order to see the sample code for an article, you have to:

  1. Download the sample ZIP file
  2. Browse to it and unzip the contents somewhere
  3. Go to Visual Studio and Open the project

I also love convenience, and that's why I made this add-in. It lets you browse The Code Project directly in Visual Studio 2005 or 2008. When you click on a link that would normally download a zip file, it asks you instead if you'd like to open the sample up using The Code Project Browser. If you say yes, the add-in will download the file, unzip it to a base My Documents\My Code Project Samples directory, then load it directly. It also provides a sidebar where you can view, reload and delete all of the projects you've downloaded.

How It's Used

Once installed, you will have a Tools > Code Project Browser menu item. Clicking that will bring up the add-in, which runs by default as a tabbed document (you can change that by right clicking the tab). NOTE: You may need to use the add-in manager if it doesn't initially show up.

VS2005 Tools Menu Screenshot

Downloading Projects

You can browse The Code Project normally using the add-in. Once you click on a sample zip file link, the following will happen:

  1. You will be prompted to open the project using the Code Project Browser. If you say no here, then the browser will handle your request and can save the zip file like you normally do. NOTE: You must be logged into the Website to download files from The Code Project.
  2. If you say yes, then the add-in will download the project and unzip it to My Documents\My Code Project Samples\[name].
    [name] is derived from the unique directory that the article and sample reside in on The Code Project.
  3. The add-in will inspect the new directory for any solutions, and if one is found, it will load it directly. If no solution is found, it will look for any project files, and if one or more are found, it will load the first one directly.
  4. An entry is created in the "Downloaded Projects" view for the new directory. All solutions, projects and sample executables will be included under the new project tree node.

The Downloaded Projects View

Downloaded Projects View

This area allows you to view, reload and delete any of the projects you've downloaded from The Code Project. To go to the "Downloaded Projects" view, click the "Downloaded Projects View" toolbar button. It's a sidebar tree view that shows all of the directories in the My Documents\My Code Project Samples directory and shows all of the solutions and projects they contain.

You can reload any project or solution from this view by double clicking on the item you want to load. There is a context menu available for all items that lets you browse to the project's article or its containing directory. You can also delete projects by selecting the directory node and pressing the delete key, or by right clicking and selecting Delete.

The Toolbar

  1. Downloaded Projects View: Shows the sidebar window with downloaded projects
  2. Back: Navigates backwards in the history list
  3. Forward: Navigates forwards in the history list
  4. Home: Navigates to the main CodeProject Web page
  5. Print Current Page: Prints the current Web page
  6. URL bar: Shows the current article URL. Also lets you type in a page to navigate to manually
  7. Navigate: Navigates to the location in the URL bar

Using the Code

All of the code for this add-in is included in the sample project at the top of this article. Because there are several articles already about writing add-ins, I'll go over some of the things that I found particularly interesting while working on this project.


This code uses the SharpZip library by ic#code to unzip the contents of downloaded ZIP files. It's always been frustrating that ZIP capability was not added to the .NET libraries, but these guys have done a great job with this library. It's available at the SharpZip Web page.

The Tool Window "Shim"

I hadn't been working on this for 15 minutes before I hit a major roadblock. I had no idea how to do something so simple as create a tool window as part of my add-in. This was unbelievably frustrating; how could this be so hard? Thirty minutes of Help browsing came up with nothing and it wasn't until I went on the Web that I found Carlos Quintero's article about how to do this. In a nutshell, creating a tool window involves using a homegrown "shim" or pseudo-host for the tool window contents, written by Craig Skibo from the Visual Studio team. I'd like to thank both of them for their published work.

I later found this article, which describes the new way to do this in Visual Studio 2005 without using the shim. Apparently, the shim was required for Visual Studio 2003, but not Visual Studio 2005. All of this goes to show one thing that I've learned from doing add-in and VSIP work... the solutions to most problems are rarely obvious or intuitive and the importance of community contributors is huge.

Downloading and Being Logged In

Again, I thought that something that would be very straightforward turned out to be quite a challenge. I intercept the Web browser's "Navigating" event and if the URL has a *.zip extension, then I assume that it is sample code and prompt the user whether or not they want to open it directly in Visual Studio. If they say yes, then I use the WebRequest/WebResponse mechanism to download the file. Sounds easy, right?

Unfortunately, The Code Project requires that you are logged in to download samples. If you log in through the Web browser, then the Web browser has established a session with The Code Project and identifies its session with a cookie, obtained at the time of the log in. Without that cookie, The Code Project thinks that the request is coming from an unknown source, and redirects to the login page. Because of this, trying to download files this way resulted in lots of downloaded login pages.

It wasn't until I found this post by Durgaprasad Gorti that I learned how this could be done using the WebRequest/WebResponse objects.

Those who used the The Code Project Browser before remember that there used to be a special separate login to use the add-in. I recently found a way to parse the needed cookies directly from the Web page owned by the Web Browser control. That means that the separate login is no longer required and you log in through the Web site, which is how I wanted it originally.

Reporting Download Progress

Both logging in and downloading files are done asynchronously using the BackgroundWorker class. One thing that I really wanted to include was progress reporting while downloading larger ZIP files. However, when requesting a ZIP file for download from The Code Project, the size of the download is not sent back in the header of the response. Consequently, without that information there's no good way to report progress. My solution was to estimate a download size of 1 meg, which is larger than most CodeProject downloads. If the size is greater than 1 meg, then the progress bar loops. It's not perfect, but at least it's a good way to at least show that progress is being made.

DTE Operations

Finally, a word about the DTE. I needed to use this object to have Visual Studio load any downloaded projects or solutions. The DTE.Solutions collection has the Open() and AddFromFile() functions, which looked perfect for doing this. Unfortunately, these functions failed horribly whenever a Visual Studio 2002/2003 project or solution version was passed as an argument.

I tried invoking the File.OpenProject command, passing the name of the project or solution. This seems to go through the proper channels and correctly launches the Conversion Wizard. It's good to get to know the commands available in Visual Studio, from both an add-in development point of view and also for being able to speed up your own productivity by binding keys to those operations. SlickEdit offers the CommandSpy as part of our free Gadgets download, which I use extensively and highly recommend.

Points of Interest

I use this add-in all the time since writing it. Here's a few tips you may find useful:

  • By default, the tool Window exists as a tabbed document so that it gets lots of real estate. I have a multi-monitor setup, and I like to float it by right clicking on the tab and selecting "Floating". I then put the tool window on the second monitor while I work in the first. That way, I get even more real estate and I can look at the article while I look at the code.
  • If you say "yes" to the add-in's prompt to open a ZIP file in Visual Studio, it may not have any projects, solutions or executables inside. This is the case with ZIP files that just contain a few code files. You can still save the ZIP like you normally would by clicking "no" when prompted by the add-in. This will forward the call to the Web browser and you'll be able to save the file normally.
  • This add-in works with Visual Studio 2005 and 2008, but will not work with Visual Studio 2003.


  • 10 Aug 2007 - Original posting
  • 16 Aug 2007 - People with non-traditional C:\Program Files\ directories were not able to use the add-in after installation, because the *.addin file pointed to an incorrect directory. I used the article by Ting Huang to update the installer to handle this case.
  • 24 Mar 2008 - Updated the installer to work with Visual Studio 2008. You can also install the add-in anywhere you like. No separate login is needed anymore, you just need to be logged into the site. This eliminates the need for favorites. An address bar was added, as well as a context menu to the project tree so that you can easily refind the article associated with a project download.


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


About the Author

SlickEdit Inc.
Web Developer
United States United States
SlickEdit Inc. provides software developers with multi-language development tools and the most advanced code editors available. Power programmers, from Fortune 500 companies to individuals, have chosen SlickEdit as their development tool of choice for over 19 years. Proven on Windows, Linux, UNIX, and Mac OS X platforms, SlickEdit products enable even the most accomplished developers to write more code faster, and more accurately. For more information about SlickEdit and free trial downloads, please visit
Group type: Organisation

1 members

Comments and Discussions

GeneralRe: Any idea on changes for Orcas Pin
Scott Dorman15-Aug-07 7:09
professionalScott Dorman15-Aug-07 7:09 
GeneralRe: Any idea on changes for Orcas Pin
SlickEdit Inc.15-Aug-07 7:31
MemberSlickEdit Inc.15-Aug-07 7:31 
GeneralRe: Any idea on changes for Orcas Pin
Scott Dorman15-Aug-07 7:48
professionalScott Dorman15-Aug-07 7:48 
GeneralRe: Any idea on changes for Orcas Pin
Scott Dorman15-Aug-07 7:56
professionalScott Dorman15-Aug-07 7:56 
GeneralVery useful - and a suggestion Pin
unsliced13-Aug-07 22:28
Memberunsliced13-Aug-07 22:28 
GeneralRe: Very useful - and a suggestion Pin
SlickEdit Inc.14-Aug-07 2:54
MemberSlickEdit Inc.14-Aug-07 2:54 
GeneralFantastic Pin
thund3rstruck10-Aug-07 18:36
Memberthund3rstruck10-Aug-07 18:36 
GeneralMade my life easy Pin
miah alom10-Aug-07 7:57
Membermiah alom10-Aug-07 7:57 
Thanks for this.....

Alomgir Miah
GeneralMore suggestions Pin
Luiz_Augusto10-Aug-07 7:53
MemberLuiz_Augusto10-Aug-07 7:53 
GeneralRe: More suggestions Pin
SlickEdit Inc.10-Aug-07 7:59
MemberSlickEdit Inc.10-Aug-07 7:59 
GeneralRe: More suggestions Pin
Mike Prilliman15-Aug-07 6:41
professionalMike Prilliman15-Aug-07 6:41 
GeneralRe: More suggestions Pin
SlickEdit Inc.15-Aug-07 6:55
MemberSlickEdit Inc.15-Aug-07 6:55 
GeneralNice one Pin
Moim Hossain10-Aug-07 6:19
MemberMoim Hossain10-Aug-07 6:19 
GeneralRe: Nice one Pin
SlickEdit Inc.10-Aug-07 6:32
MemberSlickEdit Inc.10-Aug-07 6:32 
GeneralSuggestion Pin
Chris Stefano10-Aug-07 4:07
MemberChris Stefano10-Aug-07 4:07 
GeneralRe: Suggestion Pin
SlickEdit Inc.10-Aug-07 4:21
MemberSlickEdit Inc.10-Aug-07 4:21 

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.