Search code examples
c#visual-studio-extensions

Visual Studio Extension - focus file after file is opened


I am writing a Visual Studio extension. I figured how to open a file using the following code:

dte2 = (DTE2)GetService(typeof(DTE));
dte2.ItemOperations.OpenFile("C:/TestFile.txt");  

My issue now is that the newly opened file always opened as the last "tab" in the Main Window/Code Pane and never get "focused/activated".
Can someone advise how I can get the newly opened file as the first "tab" and is focused?

Your assistance is great appreciated.

V


Solution

  • I figured. The dte2.ItemOperations works perfectly fine. It's the order of occurrence messed up the situation.