Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > How to refresh the solution explorer tree?
Ask a questionAsk a question
 

AnswerHow to refresh the solution explorer tree?

  • Wednesday, October 28, 2009 10:11 PMJeremyOp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I have been developing a package in VS2008 for C++ projects where files and folders are removed and added to the project every so often.  I have noticed recently that folders that are removed from the project do not automatically get removed from the "Solution Explorer" tree.  After, I click the "refresh" button the folder will disappear.

    I would like the "Solution Explorer" to automatically refresh upon a directory removal just like the "refresh" button does.

    I have tried to perform a refresh by activating the "Solution Explorer" window, selecting the project item, and then executing a refresh, but this throws an exception stating the command is not available.
    Dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Activate();
    
    UIHierarchy solutionExplorer = Dte2.ToolWindows.SolutionExplorer;
    UIHierarchyItem solutionItem = solutionExplorer.UIHierarchyItems.Item(1);
    UIHierarchyItem projectItem = solutionItem.UIHierarchyItems.Item(1);
    
    projectItem.Select(vsUISelectionType.vsUISelectionTypeSelect);
    
    DTE.ExecuteCommand("View.Refresh", String.Empty);
    


    Thanks

    Jeremy

Answers

  • Friday, October 30, 2009 6:51 AMWesley YaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Jeremy,

    Your code runs well on my side, have you checked is current selected item correct? or you could try to Sleep() a while after projectItem.Select() to let the Solution Explorer refresh the commands.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Friday, October 30, 2009 6:51 AMWesley YaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hi Jeremy,

    Your code runs well on my side, have you checked is current selected item correct? or you could try to Sleep() a while after projectItem.Select() to let the Solution Explorer refresh the commands.

    Sincerely,
    Wesley
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
  • Wednesday, November 04, 2009 5:13 AMWesley YaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hello,

    How are you? Is your problem resolved? May I know whether the above suggestions helped you?

    Thanks,
    Wesley


    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.