简体   繁体   中英

Copy filename extension for visual studio

Is there any extension in Visual Studio to copy file name of a selected file to clipboard or code? There are extension available in Visual Studio Code like this but not for Visual Studio.

You can use the following command (Language C#) with my Visual Commander extension to copy the file name of a selected file to clipboard:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    System.Windows.Clipboard.SetText(System.IO.Path.GetFileName(DTE.ActiveWindow.Document.FullName));
}

To insert it in code:

public void Run(EnvDTE80.DTE2 DTE, Microsoft.VisualStudio.Shell.Package package) 
{
    EnvDTE.TextSelection ts = DTE.ActiveDocument.Selection as EnvDTE.TextSelection;
    ts.Text = System.IO.Path.GetFileName(DTE.ActiveWindow.Document.FullName);
}

Sergey's answer is a workaround, and another is that you can also try to use Copy Full Path to get what you want.

Right-click on the file under Solution Explorer --> Copy Full Path and it will copy the full path of the file. Although this method includes the path, you can remove it manually, after all, this is the closest way to vs. comes.

If the two solutions do not meet your requirements, you could suggest a feature on the DC Forum . And if you do it, share the link here and anyone who is interested in it will vote it to help improve this ticket.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM