1

I'm writing a small Visual Studio extension for VS2017 in C# and I'm trying something rather simple: If I press a button I want to resurface (make active) a specific document.

I have the RunningDocumentInfo from the RunningDocumentTable for this document, so I have its moniker and hierarchy and all that stuff. In the SDK docs I only found that the resurfacing can be done with IVsUIShellOpenDocument.IsDocumentOpen and the IDO_ActivateIfOpen flag. This sounds a bit inappropriate since I already know that the document is open for sure, but I'd go with it if it works. But how do I get a fitting instance that implements IVsUIShellOpenDocument? Or is there, by any chance, a simpler way that I just didn't find?

  • See https://stackoverflow.com/questions/39414944/how-to-open-the-visual-studio-editor-programmatically-in-a-vsix-project – Sergey Vlasov Aug 18 '19 at 03:12
  • Thx for the link, this actually worked: ```EnvDTE.DTE dte; dte = (EnvDTE.DTE)Package.GetGlobalService( typeof( EnvDTE.DTE ) ); dte.ItemOperations.OpenFile( info.Moniker );``` It still feel strange to open a document you know is already open, so if there is a simpler way to just activate it I'd be more than happy, but as long as it does the trick I'm happy ^^ – Svensational Aug 18 '19 at 11:12

1 Answers1

0

I found a way I now accept as the solution:

foreach (Document doc in dte2.Documents)
{
    if (doc.FullName == Moniker)
    {
        doc.Activate();
        return;
    }
}

This traverses the currently opened documents until it finds the one I want to activate and activates it, just like I wanted :)