开发者

C# : getting folder name when right click on it

I am developing a windows application, I need to get the Folder name while right clicking on the Folder to do some operations on it .

So far I did the following :

  1. Made a registry subkey in HKKEY_CLASS_ROOT\Folder\shell\(my program name)
  2. Made a registry subkey of my program name\command [the path of my program]

now I made the registry key to be displayed in folder context menu. And in my application I did the following :

1- in program.cs

    static void Main(string[] args)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form1 p = new Form1();
        if (args.Length > 0)
        {
            p.pathkey = args[0];
        }
        Application.Run(p);
    }

2- in my form1 :

    private string _pathkey;
    public string pathkey
    {
        get { return _pathkey; }
        set { _pathkey = value; }
    }

    private void Form1_Load(object sender, EventArgs e)
    { 
        if (this.pathkey != null)
        {
           textBox1.Text=pathkey;
        }
    }

finally :

now when I right click on a folder lets say for example called NEW. then textbox3.text = C:\NEW , so far it works fine but if the folder name is New Folder then textbox3.text = C:\New only not C:\New Folder and that is my problem开发者_运维问答 if args.length > 0 it does only display the the lenght 0 not the full path.


You need to put the %0 in the registry in quotes to force the entire path to be treated as a single argument.
Otherwise, the spaces are treated as argument separators.

You could also call String.Join(" ", args) to manually recombine all of the arguments, but the first way is better.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜