开发者

How to pass all selected files names to C# application?

开发者 https://www.devze.com 2022-12-16 23:32 出处:网络
I would like to select several files on my desktop (or any other folder) and pass their names to my applicati开发者_如何学运维on.

I would like to select several files on my desktop (or any other folder) and pass their names to my applicati开发者_如何学运维on.

More specifically, I've added a key to the registry such that when I right click on a jpeg file I see a new "Transform" option that actually runs my application. The question is how can I pass all selected files names to my application ?

Thanks a lot !


They should be passed by windows. Look at the command line arguments passed to your application at start up. ie. in your Main function that has a parameter of string[] args.

To illustrate:

static void Main(string[] args)
{
    if (args.Length == 0)
    {
        Console.WriteLine("Program called without arguments");
    }
    else
    {
        Console.WriteLine("Program received this arguments:");
        foreach (string arg in args)
        {
            Console.WriteLine("\t{0}", arg);
        }
    }

    // .. do other stuff
}


If this is something that you want to do while your app is already running, like for example via a drag/drop type operation then there are a few API calls that allow you to perform drag and drop type operations with Shell objects.

Lookup/google IDragSourceHelper, IDropTargetHelper, IDataObject etc.

0

精彩评论

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