Click here to Skip to main content
15,891,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello All,
I wants to add multiple selected files in a single ListView.
My program creates context menu "Add To Program" for all files in Explorer. When I select single file this menu works fine but, when I select multiple files and clickes on "Add To Program" It Opens Multiple instances of program containing single-single file.
I have attached sample code from my project.

What I have tried:

private void Form1_Load(object sender, EventArgs e)
        {
            string fileName = Environment.GetCommandLineArgs()[1];
            FileInfo f = new FileInfo(fileName);
            //AddFileIconToImageList(fileName);
            listView1.Items.Add(f.Name, listView1.Items.Count);
        }

and In Registry
HKEY_CLASSES_ROOT->*->shell->Add To Program->command->(Default)C:\Program Files (x86)\TestProject\AddToProgram\AddToProgram.exe "%1"
Posted
Updated 5-Oct-20 6:14am
v2

That's complicated: your apps command line arguments never change once the program is running, and there is no "built in" way for Windows to pass new information to an existing instance. And each instance of your app runs as a separate process, so they do not share memory or forms at all.

It's possible though: Double Clicking a File in Explorer and Adding It to Your App while it's Running[^]
 
Share this answer
 
Comments
Shruti91 5-Oct-20 5:49am    
Thank you sir, for solution. but can we add multiple file at a time? like winzip which allows to add multiple files in it?
OriginalGriff 5-Oct-20 6:12am    
Are you talking about drag'n'drop? because that's trivial ...
Shruti91 5-Oct-20 6:54am    
No, Drag n Drop implemented, no issue. I wants to add menu like Winzip and WinRar "Add to Archieve" which allows for multiple files also.
OriginalGriff 5-Oct-20 7:01am    
So what's the problem?
Remember we only get exactly what you type to work with - we get no further context at all.

Try explaining in more detail where you are stuck, and what help you need.
Richard Deeming 5-Oct-20 10:11am    
Sounds like you're trying to add a shell context menu handler:
.NET Shell Extensions - Shell Context Menus[^]
I think I know what you're trying to do. You're app is trying to launch an external application with a command line specifying which file that application should open.

Now you want that application to open multiple files.

Well, That's a problem. The app you're launching has to support doing that. If this external app is something you wrote, you can modify it so that an already running instance can be told by a new instance that it needs to open another file. An example of how to do that has already been given to you.

If the external app is NOT an app that you wrote, there is no way for you to control that yourself. The external app would have to be re-written by its vendor to support it. That's not likely to happen.
 
Share this answer
 

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