Search code examples
c#wpfregedit

C# and context menu of windows explorer


I tried to add an item to context menu of the Windows Explorer (http://www.codeproject.com/Articles/10104/Add-a-context-menu-to-the-Windows-Explorer), and it worked but I still don't know how to get the path of selected files?

I tried Environment.GetCommandLineArgs() but it only returns the path of my application and not the selected files.

Can anyone tell me how this can be done?


Solution

  • You need to set the command to pass the related path. Instead of using:

    // From the related article
    regcmd.SetValue("",this.txtPath.Text);  
    

    You should be able to use:

    string command = string.Format("\"{0}\" \"%1\"", this.txtPath.Text);
    regcmd.SetValue("", command);  
    

    This builds a command string that includes the path to your executable (this.txtPath.Text) followed by the selected item used when triggering the context menu (%1).