Alex Rivera | Logout

In VisualStudio DTE, how to get the contents of the ActiveDocument?

Asked 2012-05-15T17:59:28.627
8

I'm scripting inside VisualStudio and am trying to get the contents of the currently ActiveDocument.

This is my current solution:

var visualStudio = new API_VisualStudio_2010();

var vsDTE = visualStudio.VsAddIn.VS_Dte;

var document = (Document)vsDTE.ActiveDocument;
var textDocument = (TextDocument)document.Object("TextDocument");

var editPoint = textDocument.StartPoint.CreateEditPoint();
var text = editPoint.GetText(textDocument.EndPoint.CreateEditPoint());

panel.clear().add_SourceCodeViewer()
     .set_Text(text,  document.FullName.extension());

Is this the best way?

I got the solution from: Because ActiveDocument.Text() Would Be Too Easy...

Edit
Report

1 Answer

0

Can you give this a try?

Dim objSelection As TextSelection = DTE.ActiveDocument.Selection
answered 2012-05-15T18:04:21.107

Your Answer