0

How can I handle automatically opening a file with my Windows Forms application? As in, I double-click the file and my application pops up and knows to open the file.

I'm assuming I somehow have to add an entry in the registry or something like this, and handle command line parameters, but I can't quite figure out the way to go about this.

Attached an image for clarity, it's pretty much what I want to achieve. (I'll be using my own file extension so I don't mess up other programs as well)

enter image description here

David Makogon
  • 69,407
  • 21
  • 141
  • 189
Tim Falken
  • 15
  • 3
  • 1
    Possible duplicate of [Associate File Extension with Application](https://stackoverflow.com/questions/2681878/associate-file-extension-with-application) – ASh Feb 23 '18 at 14:47
  • There's [an answer in MSDN](https://social.msdn.microsoft.com/Forums/vstudio/en-US/630ed1d9-73f1-4cc0-bc84-04f29cffc13b/what-registry-keys-are-responsible-for-file-extension-association?forum=netfxbcl). The information about shell file extension associations is stored in the registry. – Wyck Feb 23 '18 at 14:49
  • @Wyck -- I'd like to select this as the accepted answer, but I can't because it's a comment ;) On a side-note, when a user selects "Open With" and chooses your app, they get the option to set it as a default as well, which was good enough for me. (The application then receives the path to the opened file as a parameter in the application's entry point) – Tim Falken Apr 20 '18 at 13:01

1 Answers1

0

There's an answer in MSDN about how to associate your application with an extension. The information about shell file extension associations is stored in the registry.

Or, to set it interactively, make use of the "Open With" > "Choose default program..." feature.

Wyck
  • 10,311
  • 6
  • 39
  • 60