Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Visual Studio.NET / Extensibility / February 2005

Tip: Looking for answers? Try searching our database.

How to open a specific file into a document window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Greg Taylor - 04 Feb 2005 01:41 GMT
I want to simulate what happens when the user does a File/Open and selects a
particular file.  What I expect is: if the file is in the solution, the
projectItem is selected, and the file is opened in the document area.  The
problem with the below code is that  if the file isn't associated with VS (
e.g. a txt file ), then it doesn't open insde VS.  Instead, for example a
.txt file, notepad is launched.
((EnvDTE.DTE)getService(typeof(EnvDTE.DTE))).ExecuteCommand("File.OpenFile",
fileName);
Anna-Jayne Metcalfe - 04 Feb 2005 08:32 GMT
>I want to simulate what happens when the user does a File/Open and selects
>a
[quoted text clipped - 6 lines]
> ((EnvDTE.DTE)getService(typeof(EnvDTE.DTE))).ExecuteCommand("File.OpenFile",
> fileName);

Hi Greg,

Try using something based on this:

   EnvDTE::ItemOperationsPtr ptrItemOperations =
m_pDTE->GetItemOperations();
   ptrItemOperations->OpenFile( _bstr_t(sPathName),
EnvDTE::vsViewKindTextView);

This is an unmanaged C++ version using smart pointers, but the principles
should be the same in any VS.NET language.

Kind Regards,

   Anna-Jayne Metcalfe

   Software/Product Development Consultant,
   Riverblade Limited.
   http://www.riverblade.co.uk
Greg Taylor - 04 Feb 2005 17:11 GMT
Sorry:

ItemOperations.OpenFile(fileName, EnvDTE.Constants.vsViewKindTextView);

does the same thing.   Also trying vsViewKindAny and vsViewKindPrimary for
the constant result in the same behaviour.

> >I want to simulate what happens when the user does a File/Open and selects
> >a
[quoted text clipped - 26 lines]
>     Riverblade Limited.
>     http://www.riverblade.co.uk
Greg Taylor - 04 Feb 2005 17:57 GMT
Oops,  you are correct.  Thanks!

> Sorry:
>
[quoted text clipped - 33 lines]
> >     Riverblade Limited.
> >     http://www.riverblade.co.uk
Anna-Jayne Metcalfe - 04 Feb 2005 19:04 GMT
Hi Greg,

> Oops,  you are correct.  Thanks!
>
[quoted text clipped - 5 lines]
>> for
>> the constant result in the same behaviour.

Glad to be able to help!

We actually use that code in our Visual Lint add-in to open std.lnt and
options.lnt (PC-Lint configuration files in text format) for editing inside
the IDE, so I was beginning to wonder whether we'd missed something....

Figuring out how to achieve your aims using the extensibility interfaces
seems to be more of an art than a science. A case in point: a little while
ago I posted a query here on how to catch double click events in the Output
Window. Although I didn't get any replies, we eventually realised we could
use some logic in the WindowActivated() event to achieve the same aim.

It's not at all obvious though, and there's so much experimentation and head
scratching in the process!

Good luck with your project.

Kind Regards,

   Anna-Jayne Metcalfe

   Software/Product Development Consultant,
   Riverblade Limited.
   http://www.riverblade.co.uk

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.