Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have an application that opens a file of format (.xyz).

Now my problem is if i open this file from application , it loads the file correctly.

But when i try to select the file and right click and use "Open with" and select my application, it doesn't get loaded. Only my application.exe gets launched but file is not loaded.

These are details how its implemented.
1) I have an application, that loads a dll and displays file format which it loads.
Right now two file formats it can load (.xyz ) and (.abc). for loading these types of files, two dlls are there.

2) As soon as exe is launched, it searches for dll in a folder. If it finds the dll, it extracts file format for which files can be loaded.

3) On Launching application and selecting File-> Open from menu, it displays file format in open dialog filter and on browsing and clicking open, it loads the file of that format.


But it doesn't work when i go to particular file and click Open with to open with my application.
Posted
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 1:12am    
Why do you think the file should open via "Open With..."? What did you do for this to happen?
--SA
glued-to-code 7-Nov-11 5:59am    
Yup, I didn't do anything. It was my mistake.

You need to use the Environment.GetCommandLineArgs function to get the name of the file clicked and then open it. Something like this:-

C#
string[] appArgs = Environment.GetCommandLineArgs();
string fileName = String.Empty;
if(args.Length >= 2)
{
    fileName = args[1];
}


Put this in your Main() function.

Hope this helps
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Nov-11 1:10am    
I voted 4 this time; this is correct but low-level; and the advice to put it in Main is not clear. OP's question suggests that with his level of experience he may have a problem with that.

As always, I advise to use my CodeProject article with a library with detail usage samples, please see.
--SA
glued-to-code 7-Nov-11 7:37am    
Thanks, This did the trick for me.
It looks like you think that it should happen "automatically". Why? What have you done for this to happen?
Among other thing, you can use my library which is very simple in use and good to maintain the application: Enumeration-based Command Line Utility[^].

—SA
 
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