Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / C#

Find File in Solution

Rate me:
Please Sign up or sign in to vote.
5.00/5 (23 votes)
28 Mar 2010CPOL6 min read 110.4K   3K   48   46
Find any file in solution using incremental search and advanced filtering

Main Window

Find File in Solution main window

Contents

Introduction

Finding a file in a big solution may be a hard and daunting task. It is especially true when the solution contains tens of projects organized in complex hierarchy. Unfortunately, Visual Studio IDE doesn't provide a convenient way to find an arbitrary file in the solution. Find File in Solution AddIn solves this annoying problem.

Installation

Installation of Find File in Solution AddIn is very simple: just copy the binary files in one of the predefined folders where Visual Studio looks for add-ins. This article explains the matter in great details: INFO: Default .AddIn file locations for Visual Studio add-ins. I personally prefer the following path:

  • Windows XP: "C:\Documents and Settings\<username>\<mydocuments>\Visual Studio 2005\AddIns" (2008 for Visual Studio 2008)
  • Windows Vista/7: "C:\Users\<username>\Documents\Visual Studio 2005\AddIns" (2008 for Visual Studio 2008)

Note for Visual Studio 2005 users: Open SlnFileFind.AddIn file with Notepad and change HostApplication/Version nodes value to 8.0:

XML
<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
    <HostApplication>
        <Name>Microsoft Visual Studio</Name>
        <Version>8.0</Version>
    </HostApplication>
    ...
</Extensibility>

When the files are copied to a folder, restart Visual Studio to reload its add-ins.

Visual Studio Command "open (of)" - Almost Right

Actually, VS IDE allows to open an arbitrary file without spelunking into solution projects. It is done with wonderful "Find" combo box located on the Standard toolbar. Ctrl+D shortcut brings keyboard focus to the combo. Then, just type '>' symbol (without quotes) to enter the universe of VS IDE internal commands. The command that opens a file is, well, open (or short alias: of). After the command name, you just start typing a filename and drop-down list will show the available files:

VS IDE `of' command

VS IDE `of' command in action

Unfortunately, there is one fundamental flaw in this feature: you must know the filename beforehand and you must type it exactly how it starts. Otherwise, of command won't find anything. This limitation makes the of command practically useless.

Using Find File in Solution

Well, usage is very straightforward and simple. Open the Find File in Solution main window either from main menu or by hitting Ctrl+Alt+Y shortcut and start typing a filename.

Find File in Solution menu

Find File in Solution menu

When you are satisfied with the search result, then press TAB or DOWN ARROW key to select files. You may select several files by holding SHIFT key or using CTRL key and mouse. File selection works exactly as in a regular Windows Explorer window. Press ENTER to open selected files or ESC to dismiss the dialog.

The Find File in Solution main window is a regular Visual Studio tool window. It means that it can be floating, docked to either side or autohidden as any other IDE window. Using Ctrl+Alt+Y shortcut or selecting Find File in Solution item from the main menu will always bring keyboard focus to the search box.

Note: Upon solution opening Find File in Solution starts scanning solution tree for files. It happens in a separate worker thread rather than in the main IDE thread in order to preserve IDE responsiveness. That's why if the solution is very big, then Find File in Solution may show empty window for several seconds immediately after the solution is opened. It is normal behavior. Regardless of that, you can start typing the search string right away. When all files are fully loaded, Find File in Solution main window will be populated with correct results. It takes a huge solution to see this effect, though.

Following are the examples of possible search patterns.

Simple Search

Simple Search

Typing a string in the search box brings all files that contain this string in their filename.

Multiple Search

Multiple Search

Typing multiple substrings brings all files that contain all of the substrings in their filename.

Excluding Files From Search

Negative Match

Prepend substrings with hyphen to exclude matching files from search results.

Searching by Full Path

By default Find File in Solution searches by filename. You may search by full path by starting search string with backslash. It may be useful for finding only those files that belong to a certain directory.

Search by path

Sorting Results

Sorting Results

Search results can be sorted by clicking on column header.

Tweaking Find File in Solution

Tweaking is not recommended for ordinary users but sometimes it may be useful for a user with special needs or extremely fast/slow typing person. The secret of Find File in Solution responsiveness and smooth unstrained work is that the search is not performed immediately as user types a search string. There is a small delay before the search kicks in. It is indistinguishable for humans but significant for a machine, so it can spare redundant CPU load.

In order to show tweak settings, type "settings" string (without quotes) in search box and press Ctrl+Enter.

Settings

Default delay value is 300 msec. Minimal value is 0 msec, maximal is 1000 msec.

History

  • 3rd October, 2009
    • Initial version
  • 12th October, 2009
    • Bug fix: If user tries to open a file that exists in a project but is deleted from disk, then FileNotFound exception is not caught and IDE crashes.
  • 24th October, 2009
    • Rare crash that happens during file search has been fixed
    • Performance has been improved
    • Files that belong to multiple projects will have "(Multiple projects)" string in Project column in the file list. Also, file's tool-tip for such items will list all projects that the file belongs to.
  • 5th December, 2009
    • After user opens selected files add-in's window closes only if it is in floating mode. For all other modes "Find File in Solution" window will stay opened.
    • When "Find File in Solution" is invoked, its search box is initialized with currently selected text in VSE IDE from document windows, Output pane, etc.
    • "Find File in Solution" monitors solution changes (add/remove/rename files and projects).
    • Tweak dialog has additional option - rescanning solution files on demand. Some users reported that occasionally "Find File in Solution" loses its file list. This option should remedy the problem until proper fix is found.
  • 9th December, 2009
    • Bug fix: No files are listed in add-in's window when some of the projects in solution failed to load
  • 27th February, 2010
    • Bug fix: If a file appears directly under solution folder, i.e. doesn't belong to any project, then this file is not listed in search results
  • 27th March, 2010
    • Bug fixed: Sometimes internal list of files gets out of sync with GUI. It may lead to an unhandled exception in VS IDE
    • Improved: On solution/project events only relevant cases are handled

License

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


Written By
Software Developer
Australia Australia
More than ten years of C++ native development, and counting.

Smile | :)

Comments and Discussions

 
Questionalternate file suffixes??? Pin
Member 1133658726-Dec-14 8:17
Member 1133658726-Dec-14 8:17 
Generalis there any C# version of this tool? Pin
Southmountain19-Jul-14 9:51
Southmountain19-Jul-14 9:51 
Questionvisual studio 2010? Pin
Tittle Joseph1-May-14 0:59
Tittle Joseph1-May-14 0:59 
GeneralMy vote of 5 Pin
luongnghithaicuc3-Dec-12 19:21
luongnghithaicuc3-Dec-12 19:21 
Thanks!
GeneralMultiple tab search Pin
LeonardoX223-May-11 23:36
LeonardoX223-May-11 23:36 
GeneralRe: Multiple tab search Pin
Alex Blekhman4-May-11 7:54
Alex Blekhman4-May-11 7:54 
GeneralMy vote of 5 Pin
LeonardoX223-May-11 23:27
LeonardoX223-May-11 23:27 
QuestionCool tool, but can we add more columns to it? Pin
Bill David26-Aug-10 19:58
Bill David26-Aug-10 19:58 
AnswerRe: Cool tool, but can we add more columns to it? Pin
Alex Blekhman27-Aug-10 3:11
Alex Blekhman27-Aug-10 3:11 
GeneralMy vote of 5 Pin
Double Dose8-Jul-10 10:06
Double Dose8-Jul-10 10:06 
QuestionKeyboard shortcut for closing Find File-tool Pin
Rolf Kristensen5-Apr-10 23:32
Rolf Kristensen5-Apr-10 23:32 
AnswerRe: Keyboard shortcut for closing Find File-tool Pin
Alex Blekhman5-Apr-10 23:53
Alex Blekhman5-Apr-10 23:53 
GeneralRe: Keyboard shortcut for closing Find File-tool Pin
Rolf Kristensen5-Apr-10 23:54
Rolf Kristensen5-Apr-10 23:54 
GeneralRe: Keyboard shortcut for closing Find File-tool Pin
Alex Blekhman6-Apr-10 0:05
Alex Blekhman6-Apr-10 0:05 
GeneralCrash with VS2005 Pin
Frank Aurich15-Mar-10 21:38
Frank Aurich15-Mar-10 21:38 
GeneralRe: Crash with VS2005 Pin
Alex Blekhman15-Mar-10 22:35
Alex Blekhman15-Mar-10 22:35 
GeneralRe: Crash with VS2005 Pin
Frank Aurich16-Mar-10 3:30
Frank Aurich16-Mar-10 3:30 
GeneralRe: Crash with VS2005 Pin
Alex Blekhman16-Mar-10 3:37
Alex Blekhman16-Mar-10 3:37 
GeneralRe: Crash with VS2005 Pin
Frank Aurich24-Mar-10 1:32
Frank Aurich24-Mar-10 1:32 
GeneralRe: Crash with VS2005 Pin
Alex Blekhman24-Mar-10 2:13
Alex Blekhman24-Mar-10 2:13 
GeneralRe: Crash with VS2005 Pin
Alex Blekhman27-Mar-10 6:40
Alex Blekhman27-Mar-10 6:40 
GeneralRe: Crash with VS2005 Pin
Frank Aurich28-Mar-10 20:39
Frank Aurich28-Mar-10 20:39 
GeneralRe: Crash with VS2005 Pin
Alex Blekhman28-Mar-10 21:26
Alex Blekhman28-Mar-10 21:26 
GeneralOpending a file by pressing "Enter" or double clicking on a file closes the addin [modified] Pin
David Lind2-Dec-09 6:33
David Lind2-Dec-09 6:33 
GeneralRe: Opending a file by pressing "Enter" or double clicking on a file closes the addin Pin
Alex Blekhman2-Dec-09 7:09
Alex Blekhman2-Dec-09 7:09 

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.