How to open file programmatically using EnvDTE in C#.
Asked
Active
Viewed 4,217 times
2 Answers
11
Assuming you have a hook to the correct DTE instance...
DTE.ExecuteCommand("File.OpenFile", "c:\\derp.txt");
-
3surround the path with double quotes if it has spaces – Ivan Ferrer Villa Sep 18 '15 at 18:52
-
@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. – ScottFoster1000 Jul 28 '22 at 17:42
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...

Emil
- 2,196
- 2
- 25
- 24