C# .NET - File Associations and startup - Asked By Jerry Laudat on 27-Oct-06 12:52 AM

Suppose I have a file association setup so that if the user clicks on a fileName ending with the extension *.abc   my program will load.  This part works fine.

How do I determine the filename that he clicked on?  I had hoped it would be stored in

static void Main(string[] Args)

but that didn't seem to work.

Try this will help - Amit Saxena replied to Jerry Laudat on 27-Oct-06 02:39 AM

Jerry, the possible problem which I can see with this is related to file extension association which is done in the registry.

If you want to get the file name as a part of program arguments, this should be specified while doing the association as %1.

Attached is the sample .reg file inside zip to set this association. Edit this file and provide proper path of your .abc file handler in place of dummy path which is C:\\PATH_OF_ABC_HANDLER\\ABC_HANDLER.exe

You should be able to get the file name as a part of program argument. This will work now.

Thanks

Amit

http://www.eggheadcafe.com/fileupload/-1052171516_abc.zip

The .reg file is inline below as well ::

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.abc]
@="ABC"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.abc\shell]
@="Open"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.abc\shell\open]

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\.abc\shell\open\command]
@="C:\\PATH_OF_ABC_HANDLER\\ABC_HANDLER.exe \"%1\""

You solved it. Thanks! - Jerry Laudat replied to Amit Saxena on 27-Oct-06 04:28 AM

I would never have figured that out.