198

I have a huge solution with multiple projects. Sometime I need to navigate to a file in Solution Explorer. Using the VS 2010 'Navigate To' feature I can open any file by name in Visual Studio 2010 but I want to be able to select the file in Solution Explorer as well?

Amitabh
  • 59,111
  • 42
  • 110
  • 159
  • 4
    The question was about VS2010, but in case somebody is looking at VS2013: Check out Ctrl-; for a find in the Solution Explorer or Ctrl-, for the VS2012/13 "Navigate To" feature. – John Apr 01 '15 at 12:28
  • 1
    For a native way for VS 2012 and above, check out Aaron Carlson's answer below. – Derek Morrison Jun 24 '15 at 21:43
  • I'm using Visual Studio 2022, and I was able to get this functionality through adding the free extension CodeMaid. Ctrl+M, Ctrl+F to trigger the action. – Nate W Oct 05 '22 at 18:04

15 Answers15

223

There's an option to track the active (open and viewed) item in the solution explorer. If the file is in view, the file in the solution explorer will be selected.

Tools->Options->Projects and Solutions->Track Active Item in Solution Explorer

Jeff Mercado
  • 129,526
  • 32
  • 251
  • 272
  • 42
    This settings causes that project and solution nodes are constantly expanded as I open files. After 15 minutes of working on bigger project, I have so many nodes expanded that solution explorer becomes unsuable. [DPack](http://stackoverflow.com/questions/3436222/how-to-locate-a-file-in-solution-explorer-in-visual-studio-2010/4747759#4747759) solution is IMO better. – Karel Kral Mar 24 '11 at 17:25
  • @karel-kral, I've added an answer that uses a Macro to toggle this setting which works around this expanded node issue. – Martin Hollingsworth May 04 '11 at 01:02
  • the resharper or dpack solutions listed here get round the problem Martin mentions and make this answer not the preferred option if you have either of the others available to you. – Rob Sedgwick Sep 10 '14 at 10:34
  • 2
    For VS2012+ @Aaron's answer is the best. No installing things Ctrl + [,s – BritishDeveloper Nov 02 '15 at 16:38
  • 3
    He said he only wanted to track the file "Sometimes" not all the time. Aaron Carlson's answer should be marked as the correct answer. – RayLoveless Sep 02 '16 at 22:54
  • Unfortunately this simply expands the massive list of "External Dependencies" instead of actually opening the project that contains that header file. – riv Nov 26 '18 at 14:51
177

VS2012 added a new command called SolutionExplorer.SyncWithActiveDocument. The default shortcut for c# is Ctrl+[,S

This command will navigate to the active file in the Solution Explorer.

Also, it seems that you need to have the "Track Active Item in Solution Explorer" option turned off.

Mike Chamberlain
  • 39,692
  • 27
  • 110
  • 158
Aaron Carlson
  • 5,522
  • 4
  • 31
  • 35
  • 5
    Massive oversight that this didn't go into Visual Studio 6.0. Or even earlier. WTF. – Almo Feb 21 '14 at 21:41
  • 4
    Thanks! In my **VS2013**, `Ctrl`+`[`,`S`was default set to check out file and `SolutionExplorer.SyncWithActiveDocument` was not configured. – hwcverwe Jan 27 '15 at 13:22
  • Please note that this option is only available if you are already in the solution explorer context. I mapped this command to the following shortcut: `Ctrl` + `.`. Now i can use `Ctrl` + `0` to navigate to solution explorer and then use my assigned shortcut. – ZiGiUs Feb 17 '16 at 14:54
  • 1
    @krypru, I've been using VS2015 for a while and it still works for me. Maybe it's not mapped to the same shortcut in your environment? – Aaron Carlson Oct 09 '17 at 14:13
  • This is the correct answer, works in VS2015 and VS2017 – BlackTigerX Oct 11 '17 at 00:20
  • 3
    FYI, don't need to remember the shortcut key: Solution Explorer (I'm in VS 2015) has an icon at top (double arrows) that does "Sync with Active Document". – ToolmakerSteve Mar 29 '18 at 21:28
  • 2
    VS 2017 added a "ReSharper" keyboard mapping under Tools --> Options --> Environment --> Keyboard. This maps built-in VS functionality to the equivalent ReSharper shortcut. Once you set this, you can use the `Shift` + `Alt` + `L` shortcut. – Andacious Nov 20 '18 at 15:39
  • Yes, this is best solution than Dpack, resharper and "tick track active doc" – OKEEngine May 21 '19 at 03:25
  • This is good. What I liked even better was remaping `ctrl + [ + s` to resharpers command: `shift + alt + L`. It's more intuitive. The keyboard command is: `SolutionExplorer.SyncWithActiveDocument` – goku_da_master Mar 28 '20 at 01:31
  • For all of you using german keyboard layout it's `Ctrl + ß + s` – Kr15 Oct 18 '21 at 09:34
127

With ReSharper installed Shift+Alt+L will find the current file in Solution Explorer in Visual Studio 2008+.

Eonasdan
  • 7,563
  • 8
  • 55
  • 82
Rob Willis
  • 4,706
  • 2
  • 28
  • 20
  • 4
    when you track you don't need this shortcut. – Davut Gürbüz Apr 12 '12 at 10:52
  • 6
    It is a Reshaper command. Works for me with Visual Studio 2010 with ReSharper installed. – Radim Cernej Mar 22 '13 at 22:32
  • +1; @DavutGürbüz Sometimes you need this to kick Visual Studio 2012 into start auto-tracking again. Every once in a while (despite the checkbox "... Track Active ..." being checked, Visual Studio 2012 stops tracking. This ReSharper shortcut will reenable this without having to restart Visual Studio. – Jeroen Wiert Pluimers May 27 '14 at 14:21
  • @JeroenWiertPluimers I see . I've been using DPack extension. It is very lite and easy to use. You just right click the file tab and choose Locate on the Solution Explorer. I strongly recommend it. It works all versions of VS. ReSharper is also good but we don't prefer. Because we don't use most of its features. It makes VS heavier. Tracking makes solution explorer messy. DPack is the best one. http://stackoverflow.com/a/4747759/413032 – Davut Gürbüz May 30 '14 at 10:49
  • 3
    Tracking does not have to be enabled for Shift+Alt+L to work. At least not in VS 2010, which I am using. – Tor Haugen Jul 30 '14 at 11:43
  • This works for me without tracking enabled in VS 2015 using R# 9.2. – EM0 Oct 22 '15 at 13:08
40

I found the track option to be a little annoying.

I prefer to use DPack. It contain "Locate In Solution Explorer" operation, plus many other features (some are less powerful in VS2010, like their browsers), and it's free.

Note that ReSharper also have the locate feature that works batter than DPack's (in some cases, DPack's locate won't work if the file is collapsed behind folders), but you don't want to buy ReSharper only for this feature.

HuBeZa
  • 4,715
  • 3
  • 36
  • 58
  • The most hassle-free solution ("Track Active Item" is irritating and ReSharper isn't free). – Ian Kemp Jul 03 '14 at 09:45
  • @IanKemp, it's a matter of taste. IMO the tracking is annoying because: 1. sometimes I like the sln tree to stay focus on a particular node. 2. after a while, the sln tree gets completely expanded. – HuBeZa Jul 06 '14 at 13:31
  • i have installed and worked good for me, thank you! – Trần Hữu Hiền Dec 28 '20 at 01:31
29

Brian Schmitt has a great Locate File in Solution Explorer – Visual Studio Macro post for this. The macro is extremely simple and quick. Basically it toggles the setting

Tools->Options->Projects and Solutions->Track Active Item in Solution Explorer

so that the current file ends up selected in the Solution Explorer but, because it is not left on, you don't get irritated by Solution Explorer nodes being expanded for all the files you access.

Public Sub LocateFileInSolutionExplorer()
    DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
    DTE.ExecuteCommand("View.TrackActivityinSolutionExplorer")
    DTE.ExecuteCommand("View.SolutionExplorer")
End Sub

Bind a Keyboard ShortCut to this custom macro to effectively create what should be a built-in Visual Studio feature.

Martin Hollingsworth
  • 7,249
  • 7
  • 49
  • 51
  • This really works in VS 2010 and is easier to setup than you think (tips for adding macro: http://www.helixoft.com/blog/archives/6). – user1068352 Sep 13 '13 at 13:14
  • The link posted in the first line of answer is broken. Can you fix it please ? – Tyagi Akhilesh Sep 27 '16 at 11:26
  • @TyagiAkhilesh - note that this answer (adding your own macro) is only needed if you are still using VS 2010. Newer versions have a command built in. – ToolmakerSteve Mar 29 '18 at 21:30
19

If you have ReSharper and want to add "Locate in Solution Explorer" to the tab's context menu:

  1. Go to Tools -> Customize -> Commands -> Context Menu
  2. Select "Other Context Menus | Easy MDI Document Window".
  3. Click "Add Command".
  4. Choose "Resharper" -> "ReSharper_LocateInSolutionOrAssemblyExplorer" (in VS2019, the category name was changed to "Extensions")
  5. "OK" -> "Close"

Now, when right click on any tab and you'll see a new option: Locate in Solution Explorer.

UPDATE:

Following the comment from @jeremy-paskali, you can set a keyboard shortcut for this command:

  1. Go to Tools -> Customize -> "Keyboard..."
  2. Search for "ReSharper.ReSharper_LocateInSolutionOrAssemblyExplorer" in the "Show commands containing" field and select it.
  3. Review the currently assigned shortcuts in the drop down below.
  4. Make any changes, if needed.
  5. "OK" -> "Close"
Shay
  • 1,680
  • 2
  • 26
  • 39
  • 3
    In Visual Studio 2015, if you then click the "Keyboard..." button at the bottom of the "Customize" window, you will be taken to the Options -> Environment -> Keyboard dialog. In this dialog, you can navigate to "ReSharper.ReSharper_LocateInSolutionOrAssemblyExplorer" and find or change the keyboard shortcut to this command. I discovered that my VS2015 was set to "Shift+Alt+L" and it works! – Jeremy Paskali Mar 23 '16 at 14:11
  • Chiming in more than two years later to say the context menu trick still works with VS 2017 and R# 2018.2. Thanks for this! – Michael Armes Nov 19 '18 at 16:58
  • If trying out `Shift+Alt+L` didn't work for you in VS2019, then this surely does the job. – gosr Apr 01 '20 at 16:33
17

Visual Studio 2012 has a new shortcut Ctrl [, S. Yes you have to type Ctrl [ and then release and then immediately type S (or click the little sync icon at the top of Solution Explored). It will synchronize to the item.

Of course you can change the shortcut. I think I'll try Alt+L for locate.

If you want to change the shortcut, it's command name under Options\Environment\Keyboard is SolutionExplorer.SyncWithActiveDocument.

Usually this is more useful than always tracking, which in older versions always was a disaster because it would track 100 items in a row and then be jumping all over the place...

samneric
  • 3,038
  • 2
  • 28
  • 31
Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    Great !!! In my VS2012 the combination keys are `Ctrl+', s`. So you must change `[` with quote `'`. I hope this help someone. – ferpega Oct 27 '13 at 10:42
  • 3
    _"or click the little sync icon at the top of Solution Explore"_ To me the easiest way to accomplish this in the newer versions of VS. Nice one! – Andreas Mar 09 '15 at 07:12
  • Thanks @mrt! I totally glossed over that in this answer; but you saved me from having to do some weird customization steps (or remember an obscure shortcut)...! That button should be called out more explicitly in this answer :) – Ada Richards Nov 11 '15 at 22:38
11

I know its little too late, but hope it helps someone else. The best option now is to install Microsoft Visual Studio add on called - Productivity Power Tools.

http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef

With this comes "Solution Navigator" (alternative to Solution Explorer, with a lot of benefits) - which then you can use to filter the files to only show "Open". You can even filter files to show "Edited" and "Unsaved".

friend
  • 1,909
  • 2
  • 21
  • 28
  • I am using VS 2012 and the Power Tools. I do not see a Solution Navigator anywhere. Would you like to elaborate on the subject? Like tell where exactly the Solution Navigator is found. – mark May 22 '13 at 12:00
  • Edited. Microsoft planned on doing it - but ended up migrating only parts of it. I was disappointed that they left out this one as well. – friend May 23 '13 at 00:08
6

In the event you want to only track the current file through a keyboard shortcut - the activity is "View.TrackActivityinSolutionExplorer" (assign keys here -> Tools - Options - Environment - Keyboard)

Credit (James' comment)

This worked for me

pingo
  • 167
  • 2
  • 9
  • Note this toggles the option "Track Active Item in Solution Explorer". If you don't want to keep that option ( because it's annoying ) you have to type the assigned shortcut keys twice: once to turn it on ( finds the selected item ) and then again to turn off the option. – Richard Feb 14 '13 at 11:47
  • This is exactly what I'm looking for. – Ronald Abellano Jan 17 '22 at 08:39
4

There are several build-in ways you can accomplish this nowadays:

  1. Configure VS to track the active item in Solution Explorer: This can be accomplished by selecting "Track active item in Solution Explorer" at

Tools > Settings > Projects and Solutions > General

enter image description here


  1. Use "Sync with active document": This can be accomplished in 2 ways.

    • Firing the SolutionExplorer.SyncWithActiveDocument command by using the default key combination CTRL+]+S

      CTRL+)+S if you happen to be using an AZERTY keyboard like me.

    • By using the "Sync with active document" button on top of the Solution Explorer. The button looks like 2 apposing arrows on top of each other.

      If you're version is older then VS2019 Version 16.10.2 then this button looks like this:
      enter image description here

      From VS2019 Version 16.10.2 onwards this button will look like this:
      enter image description here

      And yet again Microsoft has changed the button icon in more recent versions of VS 2022:
      enter image description here

kristofvdj88
  • 855
  • 8
  • 12
2

In Visual Studio 2010 you can turn on the "Track Active Item in Solution Explorer" option. This will mean whenever you switch between documents the new document gets selected in Solution Explorer. This can be irritating if your solution has lots of folders, because as you move around files in your solution all the folders will be left open.

Visual Studio 2012 introduced the new "Sync with Active Document" feature. Three is a button for it at the top of Solution Explorer, or you can use the shortcut Ctrl + [, S.

screenshot of sync with active document button

thelem
  • 2,642
  • 1
  • 24
  • 34
1

This is actually built in to visual studio without the need for ReSharper (which I love BTW).

http://blogs.msdn.com/b/zainnab/archive/2010/03/29/track-active-item-in-solution-explorer-vstipproj0011.aspx

Razor
  • 17,271
  • 25
  • 91
  • 138
0

For Visual Studio 2017 using a French AZERTY keyboard the command is the same as stated by Aaron Carlson but the keyboard shortcut is different.

The AZERTY keyboard shortcut to navigate to the active file for c# is Ctrl+),Ctrl+S

I checked the shortcut hadn't changed for QWERTY users in VS2017 on this page http://visualstudioshortcuts.com/2017/

PhilG
  • 9
  • 3
0

Visual Studio doesn’t offer an easy way to locate the current file you’re editing in the Solution Explorer on demand. You can set the solution explorer to always stay in sync with this simple setting:

Tools > Options > Projects and Solutions > General. Check “Track active item in Solution Explorer”.

Thanks to Cory House

MohamedHarmoush
  • 1,033
  • 11
  • 17
0

If you want to select the file in the solution explorer on command and don't want to install anything then I would recommend this macro.

I've tested it, setting the shortcut to Alt+T, and I can confirm that it works with VS 2010.

Thanks to Dan Vanderboom for writing it.

Robert Whitley
  • 1,051
  • 5
  • 14
  • 28