Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the details of the selected item in solution explorer using vs package

I am trying to create a VS package in which, I have added a menu command to the context menu, so it appears when you right click an item in the solution explorer. Now on clicking the command, I want to show a pop up with the details of the item, on which you right clicked and invoked the command.

Now how would I get information about the selected item? Is there any service I can use in order to get any details about the item?

like image 992
niruj Avatar asked Nov 02 '12 12:11

niruj


People also ask

How do I view Solution Explorer in Visual Studio?

By default, the Solution Explorer tool window appears as a pane in the upper-right side of the Visual Studio integrated development environment (IDE). If you don't see the Solution Explorer tool window, you can open it from the Visual Studio menu bar by using View > Solution Explorer, or by pressing Ctrl+Alt+L.

What can we access by using the solution explorer?

Nested under it are code files and subfolders containing pictures, data, and documents. You can also get a list of all the references in the project.

How do I view project properties in Visual Studio?

To access properties on the solution, right click the solution node in Solution Explorer and choose Properties. In the dialog, you can set project configurations for Debug or Release builds, choose which projects should be the startup project when F5 is pressed, and set code analysis options.

What is a function of the Solution Explorer window in Visual Studio?

The Solution Explorer window contains a list of the items in the current solution. A solution can contain multiple projects, and each project can contain multiple items. The Solution Explorer displays a hierarchical list of all the components, organized by project.


1 Answers

private static EnvDTE80.DTE2 GetDTE2()
    {
        return GetGlobalService(typeof(DTE)) as EnvDTE80.DTE2;
    }
private string GetSourceFilePath()
    {
        EnvDTE80.DTE2 _applicationObject = GetDTE2();
        UIHierarchy uih = _applicationObject.ToolWindows.SolutionExplorer;
        Array selectedItems = (Array)uih.SelectedItems;
        if (null != selectedItems)
        {
            foreach (UIHierarchyItem selItem in selectedItems)
            {
                ProjectItem prjItem = selItem.Object as ProjectItem;
                string filePath = prjItem.Properties.Item("FullPath").Value.ToString();
                //System.Windows.Forms.MessageBox.Show(selItem.Name + filePath);
                return filePath;
            }
        }
        return string.Empty;
    }

Above function will return the selected item(file) full path. basically get the soultion explorer from DTE2 instance and you will get all info about solution explorer from that.

like image 102
gramcha Avatar answered Sep 20 '22 17:09

gramcha