16

To accomplish this I've been right-clicking the file or directory and then selecting Show in Windows Explorer, and then copying the path out of the address bar.

Is there an add-on or macro that can make this task easier?

I'm aware that you can drag a file from Solution Explorer into the editor and it will write out the path, but when doing web development I don't always want the server path, sometimes I want the local path.

6 Answers 6

11

Look at PowerCommands extension

http://visualstudiogallery.msdn.microsoft.com/e5f41ad9-4edc-4912-bca3-91147db95b99?SRC=Home

Among others, it contains "Copy Path" command for files and folders

UPD: Also, another option: right-click the tab of open document and there will be "Copy Full Path" command. It's built-in, no extensions needed

5
  • Woo Hoo! I've been missing that functionality since I switched IDEs! Thanks MadBender!
    – leeand00
    Commented Apr 15, 2011 at 12:40
  • 1
    Hmm odd, I ran VS as administrator to setup the extension but the items aren't appearing in the context menu. I also noticed that in Tools->Options...Power Commands all command items are checked.
    – leeand00
    Commented Apr 15, 2011 at 13:30
  • Works well for me. Try to modify and save the settings, check for conflicts with other extensions, install SP1 if you don't have it. Maybe it will fix the problem
    – MadBender
    Commented Apr 15, 2011 at 15:21
  • I used it with SP1 and without, and I don't think it's main reason. Conflict with other extensions is more likely. Do you have any?
    – MadBender
    Commented Apr 15, 2011 at 16:11
  • Unfortunately not available for VS 2022
    – AntonK
    Commented Jun 1, 2022 at 1:26
10

You can just select the file in the 'Solution Explorer' file list and hit CTRL+C. It automatically copies the file path to your clipboard.

2
  • Correct. It seems to work only on folders that have the "folder" icon and on regular files, not on solution or project or properties items.
    – capawaky
    Commented Apr 19, 2017 at 14:08
  • 1
    It copies the file itself, not the path. Commented Aug 11, 2023 at 13:58
1

I've found one more option of how to solve it without plugins (for VS 2015 and above; not certain about previous versions) Go to "Tools" -> "Customize..." -> "Commands" tab. Choose "Context menu:" and "Project and Solution Context Menus | Item" and you can add any existing Command.

In order to copy path, choose Category "File" and "Copy Full Path" command. Will add button only for files in Solution Explorer. This works for projects as well but you should choose "Project and Solution Context Menus | Project" (copy path of .vcxproj file).

It doesn't work for solutions and I don't understand actually why.

1
  • 1
    in vs2022 it's a bit weird -- it works for solution, and in code window, but not for project or project item.
    – athos
    Commented Jan 31, 2023 at 14:16
1

Tools > Options > Environment > Keyboard

You can set your own shortcut keys for anything. The two that are most relevant to this post are "File.CopyFullPath" and "File.CopyRelativePath". I created my shortcut to just be used in "Text Editor" and it has worked great.

This was asked for VS2010 and I'm using VS2019, so it is an old question, but still relevant. I knew about the file header right click menu, but for some reason I didn't think about the shortcut keys until I read this question. Posting in case this results in a quicker fix for anyone else.

1
  • 1
    strangely, File.CopyRelativePath doesn't work for me as a shortcut, though I've set it in the keyboard settings in VS 2022. Commented Feb 25, 2022 at 17:50
0

The CTRL+C doesn't work for me on MSVS 2017. Use the copy as path extension here. Then right click on file in solution explorer -> Copy as path (or assign a shortcut). I find that it works very well.

0

You can right click at these 2 places:

  • on the tab of the opened file at the top of the screen
  • on the file name in the file explorer (usually on the left).

The keyboard shortcuts are the same in both places

There are 2 options:

  • Copy Path. Keyboard shortcut Opt Cmd C on Mac
  • Copy Relative Rath. Keyboard shortcut Shift Opt Cmd C on Mac

Screenshot of context menu in top tab bar

Screenshot of context menu in file explorer

This was already mentioned in other answers, but I wanted to give it more visibility, as this is the simplest way in my opinion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.