Daniel Peñalba
Daniel Peñalba

Reputation: 31847

VSPackage: How to get selected file when there is no "real" solution opened

I'm developing a VSPackage in C#, and I would like to know how to get the current file, when only a single file (or several files are opened in Visual Studio).

All works fine when there is a hierarchy (a real solution opened). But when I open a single file in Visual Studio, I cannot get the curren selection. I mean open Visual Studio (without solution) and select File -> Open -> File.

I need to get one of these: itemid, documentCookie, mkDocumentName or whatever.

I tried the following:

Upvotes: 2

Views: 1187

Answers (1)

sisve
sisve

Reputation: 19781

This sounds like something that the DTE can solve for you. Have you checked DTE2.ActiveDocument (retrieved by querying for SDTE)?

var dte = (DTE2)GetService(typeof(SDTE));
var doc = dte.ActiveDocument;
// Check doc.Name, doc.Path, doc.FullName

Upvotes: 5

Related Questions