Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically open a file in Visual Studio (2010)

I'm building a VS package, and I'm trying to send a command from the package to Visual Studio to open up a user selected file in a new tab (just like a user would do it by going to File -> Open...).

I remember seeing at some point how to do this. Can anybody refresh my memory?

like image 254
Alex Avatar asked May 19 '10 13:05

Alex


People also ask

How do I open an existing project in Visual Studio 2010?

Choose File -> Open -> Project/Solution.

How do I open a specific File in Visual Studio?

In Visual Studio, click File > Open > Folder. Navigate to the folder, and click Select Folder. This opens the folder in Solution Explorer and displays its contents, files and any subfolders.


2 Answers

I believe you want one of:

  1. IVsUIShellOpenDocument.OpenStandardEditor
  2. DTE.OpenFile
  3. DTE.ItemOperations.OpenFile

In the end, I think they all boil down to the same behavior.

like image 77
Chris Schmich Avatar answered Nov 05 '22 04:11

Chris Schmich


I like to use the DTE method ExecuteCommand("commandName") as you can test the command in the VS Command Window

In this case ExecuteCommand("File.OpenFile")

You can add parameters to the command in a second optional string parameter if you wish.

like image 35
philiphobgen Avatar answered Nov 05 '22 05:11

philiphobgen