I have a Visual Studio extension project where I have implemented a custom OleMenuCommand
on the folder node 'IDM_VS_CTXT_FOLDERNODE'
(command displays when right clicking on the folder inside the Project). I want to get the selected folder path from the EnvDTE80.DTE2
object. I was able to get the folder name but couldn't get the folder path. Here is the sample code.
SelectedItems selectedItems = this.DTE.SelectedItems;
foreach(SelectedItem selectedItem in selectedItems)
{
string strName = selectedItem.Name; // returns the folder name
// strName = "Folder Name"
foreach(SelectedItem dteSelectedItem in project.DTE.SelectedItems)
{
string strSelName = dteSelectedItem.Name;
// strSelName = "Folder Name"
}
}
Unable to get the folder path from the SelectedItem
object. Help me here to get the selected folder path..
If you want to get the folder path from the SelectedItem, please try the follwoing:
SelectedItems selectedItems = this.DTE.SelectedItems;
foreach(SelectedItem selectedItem in selectedItems)
{
string strName = selectedItem.Name; // returns the folder name
// strName = "Folder Name"
foreach(SelectedItem dteSelectedItem in project.DTE.SelectedItems)
{
string strSelName = dteSelectedItem.Name;
// strSelName = "Folder Name"
ProjectItem prjItem = dteSelectedItem.Object as ProjectItem;
string filePath = prjItem.Properties.Item("FullPath").Value.ToString();
}
}
Hope it can help.