views:

76

answers:

2

Hello.

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?

Thanks!

+1  A: 

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.

Chris Schmich
Hi Chris...I don't get it though. My DTE object doesn't have any of these methods. And if I try to make a new DTE object, it gives me an error. Any suggestions?
Andrei
What assemblies are you referencing (i.e. where is your `DTE` type coming from)? The `DTE` objects mentioned above are coming from EnvDTE.dll, so try adding a reference to that. What is the error you get when trying to create a new `DTE` object? Is it a compile-time or runtime error?
Chris Schmich
I am referencing all of the ENVDTE80/100 assemblies.The error is compile-time: Cannot create an instance of the abstract class or interface 'EnvDTE80.DTE2'Also, I am running this in a VS Package (since I am building a VS package).
Andrei
+4  A: 

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.

stupid-phil
Somehow I can't find this method. Is it still available in .NET 4?
Andrei
I've just created an addin in VS2010 - the template creates a private variable:private DTE2 _applicationObject;You can get the ExecuteCommand from there...
stupid-phil
Ah, yes, I see what you mean.The thing was that now I'm building a Visual Studio Package. I can create a Visual Studio Add-In as well, but then, how would I create an instance of the add-in, that I can use in the VS package, but the add-in would still keep its _applicationObject.I hope you understand what I mean, it's somehow like using the add-in object (_applicationObject) from a WinForms application.
Andrei