How to open file programmatically using EnvDTE in C#
Asked Answered
V

2

6

How to open file programmatically using EnvDTE in C#.

Vitascope answered 18/2, 2011 at 8:47 Comment(0)
S
11

Assuming you have a hook to the correct DTE instance...

DTE.ExecuteCommand("File.OpenFile", "c:\\derp.txt");
Striker answered 8/3, 2011 at 13:44 Comment(2)
surround the path with double quotes if it has spacesKiushu
@IvanFerrerVilla's comment fixed (what seemed like an ambiguous) error about "/" is an invalid command that I was getting from VS when running the command because of spaces in the path.Caprice
Q
1

You can try the following snippet directly in the Visual Studio Console:

$DTE.ItemOperations.OpenFile("c:\derp.txt",$DTE.Constants.vsViewKindTextView)

It should open the file as long as it exists...

Questa answered 2/11, 2017 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.