Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 925055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:27:34+00:00 2026-05-15T19:27:34+00:00

I have a Visual Studio 2008 addin that when I press a certain hotkey,

  • 0

I have a Visual Studio 2008 addin that when I press a certain hotkey, it opens a specific file (different based on the context of the hotkey) and then searches that file for a specific string (again, context dependent.) Most of the time this works flawlessly, but sometimes if the file it’s opening is too big, the search will fail.

Here is a code snippet:

Window xmlWindow = Commands.Application.ItemOperations.OpenFile(objectFilename, EnvDTE.Constants.vsViewKindPrimary);
Find find = xmlWindow.Document.DTE.Find;
find.Action = vsFindAction.vsFindActionFind;
find.FindWhat = String.Format("Name=\"{0}\"", objectLocalName);
if (find.Execute() == vsFindResult.vsFindResultFound) {
     MessageBox.Show("Found!");
}

1. Is there a way to get it to always work (for example by blocking on the OpenFile)?

2. On a less important note, is there a way to search like this without having the results end up in the Find Results pane (this causes my old results to be cleared out by this search that is only used to get the cursor down to that part of the file)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:27:35+00:00Added an answer on May 15, 2026 at 7:27 pm

    If OpenFile behaves asynchronously, I’d suggest you consider changing the logic to rely on a different event, one that relies on the document being activated.

    For example, have you tried triggering the OpenFile with your shortcut key, then queuing the search so that it’s later handled by a VS event? (The code below was taken from a Visual Studio 2010 addin, but I believe the events are the same.)

    // make sure these are class variables, otherwise they may get GC’d incorrectly and break the COM interaction
    private WindowEvents _winEvents = null;
    private DTE2 _applicationObject;

    in the connect:

    _events = _applicationObject.Events;
    _winEvents = _events.get_WindowEvents();
    
    _winEvents.WindowActivated += new _dispWindowEvents_WindowActivatedEventHandler(WindowActivated);
    

    Then, you’d put some code in the WindowActivated:

    void WindowActivated(Window GotFocus, Window LostFocus)
            {
                Document gotFocusDoc = GotFocus.Document;
                if (gotFocusDoc != null)
                {
                    string fileExt = Path.GetExtension(gotFocusDoc.Name);
    

    There, you’d watch for the file that you wanted to scan (you’d maybe need to keep a list, etc.).

    For the second issue, you could just scan through the document yourself once you’ve got access in the way I suggested above.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.