topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday March 28, 2024, 4:09 am
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: C# question about registering file extension with particular application  (Read 6438 times)

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
For any of you C# coders, I'm not a professional coder.  I just like to write a few programs in my spare time.  In one of these applications, I have data files written to disk by the application using Csharp's serialization.  I give these binary files an unusual (and supposedly unique) extension, namely *.crf

Now, I'll tell you what I have been able to do, and what I'd like to be able to do...

I can, of course, open one of these files from within the program, using a file-open dialogue.  Also, I can drag and drop one of these data files onto either the executable itself, or a shortcut thereof, and the program launches and opens the file.  All well and good.  What I don't know how to do (and spent many hours trying to figure out some months ago) is this:  I want to be able to right click on the data file, then click on "Open" in the popup context menu, and have the operating system recognize that it needs to launch my application to open the file.

Now... I know how to do this by manually adding a file type in Windows.  But I need to know how to create this association programmatically.  Any pointers will be most appreciated.  I've been given sample code before, but was unable to get the sample project to work, or get the code snippet to work in my own app.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Since nobody replied, I conclude that C# isn't heavily used by members of this forum ;)  I'll report on what I've discovered:  it appears that MS Visual C# Express 2005 does not offer support for creating shell support via the built-in C# installer.  I understand that the full Visual Studio version does, but that doesn't help me.  Does anyone know of any other, free, installers, that can get Windows to automatically associate an program with a particular file extension, once installation is finished?

Eóin

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,401
    • View Profile
    • Donate to Member
Hi kyrathaba there are two very popular free installers out there: Inno Setup and Nullsoft Scriptable Install System.

Personally I use Inno, here is a sample of what a script needs to register with a file extension-
...
[Tasks]
Name: associate_app; Description: {cm:AssocFileExtension,Application,.extension}; GroupDescription: Other tasks:; Flags: unchecked

...

[Registry]
Root: HKCR; Subkey: .extension; ValueType: string; ValueName: ; ValueData: Application; Flags: uninsdeletevalue; Tasks: associate_application
Root: HKCR; Subkey: Application; ValueType: string; ValueName: ; ValueData: Extension File; Flags: uninsdeletekey; Tasks: associate_application
Root: HKCR; Subkey: Application\DefaultIcon; ValueType: string; ValueName: ; ValueData: {app}\Application.exe,0; Tasks: associate_application
Root: HKCR; Subkey: Halite\shell\open\command; ValueType: string; ValueName: ; ValueData: """{app}\Application.exe"" ""%1"""; Tasks: associate_application

...

That script registers "Application" with ".extension" files. So you can change the word "Application" and "extension" to fit your needs. If the above is a bit confusing read the FAQ entry.

kyrathaba

  • N.A.N.Y. Organizer
  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 3,200
    • View Profile
    • Donate to Member
Thank you VERY much Eoin.  I have Inno Setup, but have never used it.  I'll have to dig it out and play around with it.  My thanks.

- kyrathaba