locked
open file.cs (no project item) from my add in RRS feed

  • Question

  • Hi,

    my question is open a file.cs (in default editor c#) from disk (no project item)  in my visual studio add in. 

    it is possible?

    sorry for my english.

     

    Thursday, April 8, 2010 8:08 AM

Answers

  • Hi,

    The method you need is:

        EnvDTE.DTE2::OpenFile

    The code to open any file in the editor follows below:

    EnvDTE.Window theWindow = _applicationObject.OpenFile(EnvDTE.Constants.vsViewKindCode, @"... your filename ...");
    
    theWindow.Visible = true;
    

    _applicationObject here is just the EnvDTE.DTE2 interface you get with an Addin. If you are using a package, you will need to locate the EnvDTE.DTE2 interface from somewhere and then invoke OpenFile.

    Graham

     

    • Marked as answer by Fabio Menta Thursday, April 8, 2010 4:10 PM
    Thursday, April 8, 2010 10:11 AM

All replies

  • Hi,

    The method you need is:

        EnvDTE.DTE2::OpenFile

    The code to open any file in the editor follows below:

    EnvDTE.Window theWindow = _applicationObject.OpenFile(EnvDTE.Constants.vsViewKindCode, @"... your filename ...");
    
    theWindow.Visible = true;
    

    _applicationObject here is just the EnvDTE.DTE2 interface you get with an Addin. If you are using a package, you will need to locate the EnvDTE.DTE2 interface from somewhere and then invoke OpenFile.

    Graham

     

    • Marked as answer by Fabio Menta Thursday, April 8, 2010 4:10 PM
    Thursday, April 8, 2010 10:11 AM
  • Thanks
    Thursday, April 8, 2010 4:09 PM