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

Visual Studio Project MRU List Editor

, 28 Jun 2005
Rate this:
Please Sign up or sign in to vote.
A tool for editing the "Start Page" Recent Project List in Visual Studio .NET.

Introduction

Anyone who has used Visual Studio to create more than one project or solution has used the "Start Page" to see the most recently used (MRU) projects or solutions. If you are like me, you often have more than one Visual Studio instance opened and have been frustrated by the fact that the list never seems to be "right". In addition I find myself often creating "temporary" projects to test a new idea and don't want to see these projects on my MRU Project List.

I have seen two articles on CodeProject discussing the "Start Page", but neither gave me an easy way to edit or maintain this list. The Stagner article speaks of maintaining the list by editing the registry, which in the end is all my tool does, but I wanted an interface to maintain the list.

Background

Visual Studio stores the MRU Projects in the registry under the path HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\XX\ProjectMRUList where XX is the version number of Visual Studio.

  • Visual Studio 2002 - 7.0
  • Visual Studio 2003 - 7.1
  • Visual Studio 2005 - 8.0

There is a string value for each recent file named File1, File2, File3, etc. with a value of the full path to the file. Visual Studio updates this list on close, which is the root of some of my problems. Multiple versions of Visual Studio do not communicate about their open projects, nor do they read the current state of the registry and attempt to merge them. On close, Studio clears this key and re-writes out the list as it knows it. My scenario is as follows:

  • Open a copy of Visual Studio and create Project 1
  • Open a second copy of Visual Studio and create Project 2
  • Close the second copy of Visual Studio. Project 2 is written out to the Registry.
  • Close the first copy of Visual Studio. The Key is cleared and Project 1 is written out to the Registry.
  • Open Visual Studio again to find that it "forgot" about Project 2.

Important Note

Since Visual Studio clears and rewrites the list on close, you must have all instances of Visual Studio before using this tool.

Using the code

There is no real magic in this code; one listbox, six buttons and some Registry code.

Since we are using the Registry, we need to include the Microsoft.Win32 namespace.

    using Microsoft.Win32;

On the form load we open the key in a writable mode:

    private void MainForm_Load(object sender, System.EventArgs e) {
        // Open a writable RegKey
        m_ProjectMRUKey = Registry.CurrentUser.OpenSubKey(PROJECT_MRU_PATH, true);
    }

Loading and daving methods:

    /// <SUMMARY>
    /// Loads (Reads) Registry Values into ListBox
    /// </SUMMARY>
    private void btnLoad_Click(object sender, System.EventArgs e) {
        lstBoxMain.Items.Clear();
        foreach (string key in m_ProjectMRUKey.GetValueNames()) {
            lstBoxMain.Items.Add(m_ProjectMRUKey.GetValue(key));
        }
    }

    /// <SUMMARY>
    /// Save (Writes) Registry Values from ListBox
    /// </SUMMARY>
    private void btnSave_Click(object sender, System.EventArgs e) {
        foreach (string key in m_ProjectMRUKey.GetValueNames())
            m_ProjectMRUKey.DeleteValue(key);

        for(int i=0; i < lstBoxMain.Items.Count; ++i) {
            m_ProjectMRUKey.SetValue("File" + (i+1), lstBoxMain.Items[i]);
        }
        //Flush the object to force it to write the files to the Registry
        m_ProjectMRUKey.Flush();
    }

Form closing - Close the Registry key:

    private void MainForm_Closed(object sender, System.EventArgs e) {
        //Close and flush the registry value on close
        m_ProjectMRUKey.Close();
    }

The rest of the code deals with maintaining the ListBox by removing the selected item, or moving it up or down in order. There is also an Add button to create a new item in the list for unknown projects. Note that the OpenFileDialog called in the Add function only filters to look for a small subset of the total Visual Studio supported file types. It was enough to suit my needs and I added an "All Files" filter as a catch-all.

Final Thoughts

As the radio cliché goes, "I'm a long time listener first time caller to CodeProject". I hope this simple article is useful to those who take the time to read it. I use this tool all the time and have found it very helpful. Depending on how my experience with this article goes, I will hopefully be back to lend more tips and tricks to the coding community. I look forward to your comments and / or questions.

History

  • Version 1.0: Initial release.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Josh Beach
Web Developer
United States United States
No Biography provided

Comments and Discussions

 
GeneralLatest version Pinmemberpeterchen6-Apr-07 1:26 
Generalstart page PinmemberMoekie3-Oct-06 1:46 
GeneralModified the MRU program PinmemberAchintya Jha12-Sep-06 11:13 
GeneralRe: Modified the MRU program PinmemberJ. Beach12-Sep-06 17:05 
GeneralRe: Modified the MRU program PinmemberAchintya Jha13-Sep-06 5:27 
GeneralWack them projects away PinmemberIC1826-Jun-06 11:18 
QuestionThe name 'm_ProjectMRUKey' does not exist in the current context PinmemberSeoulborn12-Jun-06 12:41 
AnswerRe: The name 'm_ProjectMRUKey' does not exist in the current context [modified] PinmemberJosh Beach12-Jun-06 18:43 
GeneralAt last, success .... PinmemberKhurram Hassan12-Apr-06 21:16 
A nifty utility Big Grin | :-D Quite a few of the entries in my mrulist were driving me up the wall. Now they are all gone. Thanks.
GeneralA wonderful tool! PinmemberTroye Stonich27-Dec-05 7:46 
GeneralList ordered by dates PinmemberChrisFrazier7-Jul-05 9:56 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 28 Jun 2005
Article Copyright 2005 by Josh Beach
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid