Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Multiple Files Path with Right Click

Tags:

c#

.net

I have added my application to the right click menu of Windows with the help of the registry

"C://myapp.exe "%1"

I am able to get the path of the selected file in a MessageBox using the below code.

static void Main(string[] args)
{
   foreach (string path in args)
   {
       MessageBox.Show(path);  
   }
}

It is okay if I want to open a single file, but if I select multiple files, it runs multiple instances of my application. I need the path of all selected file in the single instance only. Can anyone give me an idea of how to do this?

like image 959
Krish Avatar asked Aug 21 '13 06:08

Krish


2 Answers

A non-programming work-around, to copy all the paths simultaneously is the following (tested at Windows 7):

  1. Select the files you want.
  2. Shift+Right Click.
  3. Click "Copy As Path" (it appears as an additional option!).

All paths are copied as expected!

like image 110
Pavlos Fragkiadoulakis Avatar answered Oct 06 '22 17:10

Pavlos Fragkiadoulakis


I tried it and the application is running a new instance for each selected file. I even tried to add "%2" "%3" etc to the registry command, that also did not work.

If it is really necessary to run a single instance for all files, maybe you can setup your app as with a class derived from WindowsFormsApplicationBase, set the IsSingleInstance property and override OnStartupNextInstance (no link to that 'cause my reputation does not allow more than 2 links)

like image 24
René Vogt Avatar answered Oct 06 '22 17:10

René Vogt