سؤال

Hi I'm making a visual studio package which creates a context menu in the solution explorer when certain types of file are right clicked. I have the menu working but I need to grab the full path rather than the filename. I do this because selecting an option in the context menu opens a commandline program that takes the full path as a paremeter.

Right now it looks like this:

    foreach (var ItemSelected in vsItemSelections)
                    {
                        object value;
                        hierarchy.GetProperty(ItemSelected.itemid, (int) __VSHPROPID.VSHPROPID_Name, out value);
                        if (value != null && value.ToString().EndsWith(".rst"))
                        {
                            cmd.Visible = true;
                        }
                        else
                        {
                            cmd.Visible = false;
                            break;
                        }
                    }

So I can make the command visible in the context menu if .rst files are selected but obviously I need the full path. I've tried everything I can think of but this is a totally new area to me.

I have a solution that already works using an ENVDTE80.DTE application object but it seems awfully clunky when it runs.

هل كانت مفيدة؟

المحلول

It ultimately depends on the type of hierarchy (not all items supports a "full path" concept), but for most hierarchy, this method should get back what you need:

IVsHierarchy.GetCanonicalName(uint itemid, out string pbstrName);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top