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.