Click here to Skip to main content
15,905,614 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the func that create item in context menu of specified file.
How to get path of file, which was clicked? Thanks.
C#
using Microsoft.Win32;
//Extension - Extension of the file (.zip, .txt etc.)
//MenuName - Name for the menu item (Play, Open etc.)
//MenuDescription - The actual text that will be shown
//MenuCommand - Path to executable
private bool AddContextMenuItem(string Extension,
  string MenuName, string MenuDescription, string MenuCommand)
{
  bool ret = false;
  RegistryKey rkey =
    Registry.ClassesRoot.OpenSubKey(Extension);
  if(rkey != null)
  {
    string extstring = rkey.GetValue("").ToString();
    rkey.Close();
    if( extstring != null )
    {
      if( extstring.Length > 0 )
      {
        rkey = Registry.ClassesRoot.OpenSubKey(
          extstring,true);
        if(rkey != null)
        {
          string strkey = "shell\\" + MenuName + "\\command";
          RegistryKey subky = rkey.CreateSubKey(strkey);
          if(subky != null)
          {
            subky.SetValue("",MenuCommand);
            subky.Close();
            subky = rkey.OpenSubKey("shell\\" +
              MenuName, true);
            if(subky != null)
            {
              subky.SetValue("",MenuDescription);
              subky.Close();
            }
            ret = true;
          }
          rkey.Close();
        }
      }
    }
  }
  return ret;
}
Posted
Comments
RobScripta 29-Oct-12 7:57am    
I haven't studied your code, because I'm wondering why you don't use System.Windows.Forms.OpenFileDialog?

1 solution

C#
if(subky != null)
{
   subky.SetValue("",MenuCommand + " \"%1\");
   ...
}


The "%1" will give you the filename which was selected
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900