Click here to Skip to main content
Click here to Skip to main content

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

By , 27 Mar 2008
 
Prize winner in Competition "Best C# article of Jul 2007"
Code Project Browser Addin screenshot

Introduction

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

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.

SharpZipLib

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.

History

  • 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.

License

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
Member
Organisation
1 members

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 http://www.slickedit.com.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionwrong local header signaturememberTarek Elqusi10 Jan '13 - 18:59 
I tried to use this application and when clicked on the source zip file it gave me
wrong local header signature:0x4F44213C. It gave me this number for several links, please help
GeneralMy vote of 5memberkhoidh26 Oct '10 - 20:36 
Great, thank very much the author SlickEdit Inc.
QuestionVS2010memberSteven J.H.2 Sep '10 - 3:25 
Great Program!
 
Is there going to be a version for VS2010 ?
GeneralAdd-in doesn't show in VS2008 ExpressmemberKraeven5 Aug '09 - 1:46 
How do I get the add-in working in Visual Studio Express VB 2008?
Or is this not possible?
GeneralRe: Add-in doesn't show in VS2008 ExpressgroupSlickEdit Inc.6 Aug '09 - 2:54 
I don't think that's possible in the express versions of Visual Studio.
QuestionCan compile cannot runmemberu060509413 May '09 - 23:56 
I create an add-in solution, put all src files inside CPBrowserAddin\CPBrowserAddin and inside them in the project, but can compile cannot run?
Generaldisplay addin usercontrolmemberaowen15 Dec '08 - 4:07 
hi
 
i've studied the source and copied it. it's virtualy the same, only the names or paths are diffrent. it just never displays my usercontrol but it's created and goes through the InitializeComponent() method. has anyone got some tipps for me?
General[Message Removed]memberKatekortez25 Oct '08 - 9:07 
Spam message removed
GeneralSuggestionmemberRyanEK27 Jul '08 - 21:34 
Thanks for a great add-in! A handy feature would be the ability to create my own directories and then have the ability to drag and drop the project folders. I could then create my own project groupings instead of managing a long list Smile | :)
 
Ry
QuestionError while downloading the projectsmemberbhaskar babu11 Jun '08 - 22:23 
When I click on yes to the add to the code project browser i am getting an error which says,
 
Error downloading file: The 'Value'=81,152,153,154' part of the cookie is invalid
 

I am using a proxy server for internet, otherthan this i dont get any error.
AnswerRe: Error while downloading the projectsmemberscott_hackett12 Jun '08 - 2:33 
I'm not sure I understand what you mean by "clicking yes to add the code project browser". Are you talking about installing it, or clicking yes when downloading a project? Unfortunately I don;t have an environment where I can work through a proxy server so it's tough to test and know exactly what's going on in your environment... any chance the code can be stepped through for a closer look at where that failure is happening?
GeneralThanks !memberBillWoodruff27 Mar '08 - 6:18 
Many thanks for this excellent contribution to the CP community. To me it carries a "sub-text" that you work for a progresive and responsible company worthy of respect.
 
best, Bill Woodruff
dotScience
Chiang Mai, Thailand
 
"The greater the social and cultural distances between people, the more magical the light that can spring from their contact." Milan Kundera in Testaments Trahis

GeneralRe: Thanks !memberscott_hackett27 Mar '08 - 7:31 
Thanks, I'm glad you like it! Sorry it took so long to get the fix up, it's been really busy here. Thanks again for the nice compliment.
 
Scott
GeneralRe: Thanks !adminChris Maunder21 Apr '08 - 15:19 
Actually, Scott, my apologies for not keeping you guys in the loop during the reorg of the site.
 
cheers,
Chris Maunder
CodeProject.com : C++ MVP

Question404 error when trying to have the tool download the zip filememberClark Wilson10 Dec '07 - 12:17 
I've been using the add-in for weeks successfully.
 
Now when I try to download code for the tool to handle I'm getting a 404 (page not found) followed by an "empty path not allowed" or some such. I also get a 404 if I click on the "log in to Code Project" button that the tool puts up. But a direct login via the web page works okay both in the tool and in a separate browser.
 
My speculation is that the site changed something and broke the tool access.
 
Are others having the problem?
GeneralRe: 404 error when trying to have the tool download the zip filememberSlickEdit Inc.11 Dec '07 - 4:32 
Yes, I noticed the same thing last night. It does have to do with the site re-org and the way logging in happens. I'll look into it and post a fixed version as soon as I can. Thanks!
GeneralRe: 404 error when trying to have the tool download the zip filememberHosmerica11 Dec '07 - 7:37 
I know you already know about this and are working on it, Slick, but I too am getting this error.
GeneralRe: 404 error when trying to have the tool download the zip filememberSlickEdit Inc.11 Dec '07 - 10:08 
Yeah, I suspect that everyone using it is getting this error. Sorry for the inconvenience.
QuestionRe: 404 error when trying to have the tool download the zip filememberThe_Badman25 Feb '08 - 8:16 
any update on a fix for this?
GeneralRe: 404 error when trying to have the tool download the zip filememberSlickEdit Inc.27 Feb '08 - 7:56 
Sorry to have let this go for a while now. I do have a fix for this that includes other nice improvements, and I will be posting that up here within the week.
GeneralRe: 404 error when trying to have the tool download the zip filememberscott_hackett27 Mar '08 - 8:03 
The update has been posted, thanks for being patient!
GeneralLoading documentsmemberBigBenDk29 Nov '07 - 1:42 
Hi
 
I am currently working on an add-in, and your sample helped a lot getting to understand the nuts and bolts of Visual Studio.
 
However, I am creating custom documents inside Visual Studio, for editing object loaded from WCF services.
 
When you create the browser window you use the IWindows2.CreateToolwindow, and then sets the .floating = false; but it has it drawbacks.
 
When doing changes, it does not mark the window as changed - and the save-button stays disabled.
 
Do you have any idea on how to add a document to Visual Studio, instead of creating a toolwindow?
 
Again, great article Big Grin | :-D
GeneralRe: Loading documentsmemberSlickEdit Inc.29 Nov '07 - 3:10 
Yes, a tool window is considerably different than a document window. I set it to floating=false because that gives it a nice initial appearance, but it can be "unfloated" to work independently, for instance on a second monitor.
 
AFAIK, a document must have an associated file. I don't believe that Visual Studio has the concept of a file-less buffer. If you are making a custom editor for a file, I believe you will need the VSIP SDK, and there are several good samples in the SDK to show you how to do that.
 
If you just want to open the file in a regular VS document, you can call:
 
dte.ItemOperations.OpenFile(fileName, "");
 
Hope that answers your question, let me know if I didn't.
GeneralRe: Loading documentsmemberBigBenDk29 Nov '07 - 12:03 
Thank you for the reply.
 
What I want to do is:
 
* Request an object from a WCF service, like a Customer object, and load it into a UserControl with the correct fields.
 
* Display the UserControl as a document, and save the changed Customer object back to the server, when the Save button is pushed.
 
I got all the service kinks sorted out - but the document part eludes me.
 
I looked at the VSIP SDK, it has good samples, but it seems very complex for such a simple task.
As you say, editors seems to be tightly bound to the file/extension.
 
Team Foundation Server client does something similar to what I want, so it should be possible.
 
Any help would be great!
GeneralRe: Loading documentsmemberSlickEdit Inc.30 Nov '07 - 3:45 
The VSIP SDK is definitely not trivial, and you will need it to do what you are saying you want to do. I recommend creating a new project of type "Other Project Types > Extensibility > Visual Studio Integration Package". Specify that you want your package to include a custom editor named "MyEditor". This creates a sample project that implements a fully functional editor using a Rich Text Box as its base. It's completely overkill for what you are trying to do, but it will give you some good insight for working through your project.
 
For instance, look at EditorPane's implementation of OnTextChange to see how to notify Visual Studio of status changes using the ITrackSelection interface.
 
I haven't personally done the type of thing you're after, but this is how I find my way through VSIP stuff most of the time... by taking a sample and taking only what's necessary.
GeneralRe: Loading documentsmemberBigBenDk30 Nov '07 - 4:20 
Thanks, great advice!
 
Ill digg through the VSIP SKD, and drop you a line when I find the solution.
 
Have a nice weekend.
Generalsignmemberzhaojicheng28 Nov '07 - 17:22 
When I sign into the codeproject throught add-in.
But the web page display the email and password still.Why??
GeneralRe: signmemberSlickEdit Inc.29 Nov '07 - 3:01 
I tried to explain in the article, but the add-in downloads the zip files itself. To do this, it must authenticate with the Code Project site using the user name and password, because you have to be signed in to download files. The add-in can't get those login credentials from the web browser, so the login mechanism on the actual web page, and the login that the add-in asks for are independent. Hope that helps clarify.
GeneralSign-in: 404 ErrormemberSTLMike18 Dec '07 - 8:03 
Hey! Great article and good looking app; however, when I try to login I get a 404 error saying the page is not found. I also wonder what would happen if cp changes their login page; will it cause the app to break?
 

 
Thanks!
 

Mike
 

www.LANdango.com
Mike

GeneralRe: Sign-in: 404 ErrormemberSlickEdit Inc.19 Dec '07 - 4:02 
Thanks for posting the bug. I have a fix that I'm going to be putting up soon that fixes this problem and adds some of the changes people have asked for.
GeneralProxy authentication requiredmemberjfuhry23 Oct '07 - 3:01 
A heads up for others who see this error when opening the Code Project Browser. You'll need to add your proxy server URL to the VS2005 config file as described in KnowledgeBase article 910804 http://support.microsoft.com/kb/910804[^]
 
Jeff Fuhry

Generalnice piece of workmemberPiascas8 Oct '07 - 4:30 
Very nice addin, i find it very usefull.
 
thanks
GeneralRe: nice piece of workmemberbitumen200325 Oct '07 - 12:37 
I agree very nice, and smooth, good work
QuestionVS2008 BetamemberGreg Russell26 Sep '07 - 5:15 
Excuse me if I'm naive. Will this work in VS2008 Beta?Smile | :)
AnswerRe: VS2008 BetamemberSlickEdit Inc.26 Sep '07 - 5:37 
Yes, it should work fine.
GeneralRe: VS2008 BetamemberYifeng Ding26 Sep '07 - 13:55 
No, it does not work in VS2008 Beta2. I've already tested.
During installation, a "CPBroswer.Addin" file is copied to "My Document\Visual Studio 2005\Addins". But for VS2008, the directory name is "Visual Studio 2008".
Even I copy the add-in file manually to the appropriate directory, it still not shown in the Add-in Manager.
AnswerRe: VS2008 Betamembersemog4 Oct '07 - 11:48 
You need to edit the .AddIn file.   Change the version numbers required from 8.0 to 9.0.   Here are the replacement sections you will need to change:
 
<HostApplication>
     <Name>Microsoft Visual Studio Macros</Name>
     <Version>9.0</Version>
</HostApplication>
<HostApplication>
     <Name>Microsoft Visual Studio</Name>
     <Version>9.0</Version>
</HostApplication>

GeneralsuggestionsmemberYifeng Ding25 Sep '07 - 21:31 
1. Gives user a chance to choose where to save downloaded files and whether to save user name and password.
2. Adds a search function.
3. Grabs status text of the WebBrowser control and show in status bar of VS IDE.
4. Downloaded projects and favorites management.
5. ...... Smile | :)
GeneralRe: suggestionsmemberSlickEdit Inc.26 Sep '07 - 3:00 
Those are great suggestions. I'll try to get as much of that into the next version as possible. Thanks again for your interest in the project!
GeneralRe: suggestionsmemberYifeng Ding26 Sep '07 - 13:47 
You're welcome!Big Grin | :-D
QuestionI have Visual C# 2005 Express edition, can i use thismemberRajesh Naik Ponda Goa25 Sep '07 - 20:56 
Can I use this addin in Visual C# 2005 Express edition, I installed this msi, but I could not find this addin in Tool menu. Do I need to do any changes for this add-in to work in this edition??
AnswerRe: I have Visual C# 2005 Express edition, can i use thismemberYifeng Ding25 Sep '07 - 21:36 
You may enable this add-in manually.
The Add-in Manager can be found in the Tool menu. In the manager dialog box, just check the "Code Project Browser", and then, enjoy.
AnswerRe: I have Visual C# 2005 Express edition, can i use thismemberSlickEdit Inc.26 Sep '07 - 2:59 
Unfortunately, the Express versions of Visual Studio do not support add-ins.
GeneralNicely donemembermikemac434425 Sep '07 - 11:56 
Great idea nicely implemented. Thanks.
Generalerror installing 2869memberwebbuilder25 Sep '07 - 4:09 
I'm sure it's a simple one. Vista/vs2005. I am also unsing MSOneCare
Thanks
Looking forward to using this.
KES
 
Share the knowledge.
I can use all the help I can get and so do YOU!
KES

GeneralRe: error installing 2869memberWoody10025 Sep '07 - 11:47 
Yep Im getting the same error.Cry | :(( I'm also using Vista, however I have multi boot available (either XP or Vista).
 
I will try to install onto the XP side and see what happens.
Cheers

 
Graeme
GeneralRe: error installing 2869memberNickNelson26 Sep '07 - 1:18 
After a bit of googling etc I've found that it's a permissions problem that can occur when using msi's that interact with another program (in this case vs2005). I turned off UAC (User Account Control), restarted my PC and ran the installer again - this time it ran perfectly. Don't forget to turn on UAC again afterwards.
 
Nick
 
Nick

GeneralRe: error installing 2869memberwebbuilder26 Sep '07 - 3:51 
that did it. Thank's
KES
 
Share the knowledge.
I can use all the help I can get and so do YOU!
KES

AnswerRe: error installing 2869memberDanielTheCoder26 Oct '07 - 7:19 
In Vista you don't need to disable UAC.
start msi with admin rights, then its working.
 
or
open a command line with admin rights and start the msi package from there
 
Daniel
GeneralProblem with the Code Project BrowsermemberStotty24 Sep '07 - 21:50 
Looks a good tool, but when I click on the download source file I get the error:-
 
"Error downloading project, make sure you are logged in correctly by using the Login button on the toolbar"
 
1) I am logged in.
2) When I press the Login button on the toolbar nothing happens.
 
If I just download the file in the usual way it's fine so that would suggest I'm logged in properly.
 
Cry | :((
 
Stotty

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 27 Mar 2008
Article Copyright 2007 by SlickEdit Inc.
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid