1

I a made C# program that opens and show sdf files (sqlCE).

How to make it so (on my program installation) that all *.sdf files

in my computer will be opened with my program ?

Thanks in advance.

CrazyCasta
  • 26,917
  • 4
  • 45
  • 72
Gali
  • 14,511
  • 28
  • 80
  • 105

1 Answers1

3

A Full Example you can use easily: C# Set File Type Association

You'll need to create a key under HKEY_CLASSES_ROOT with the name set to your file extension (eg: ".txt"). Set the default value of this key to a unique name for your file type, such as "Acme.TextFile". Then create another key under HKEY_CLASSES_ROOT with the name set to "Acme.TextFile". Add a subkey called "DefaultIcon" and set the default value of the key to the file containing the icon you wish to use for this file type. Add another sibling called "shell". Under the "shell" key, add a key for each action you wish to have available via the Explorer context menu, setting the default value for each key to the path to your executable followed by a space and "%1" to represent the path to the file selected.

For instance, here's a sample registry file to create an association between .txt files and EmEditor:

[HKEY_CLASSES_ROOT\.txt]
@="emeditor.txt"

[HKEY_CLASSES_ROOT\emeditor.txt]
@="Text Document"

[HKEY_CLASSES_ROOT\emeditor.txt\DefaultIcon]
@="%SystemRoot%\\SysWow64\\imageres.dll,-102"

[HKEY_CLASSES_ROOT\emeditor.txt\shell]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\open]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\open\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" \"%1\""

[HKEY_CLASSES_ROOT\emeditor.txt\shell\print]

[HKEY_CLASSES_ROOT\emeditor.txt\shell\print\command]
@="\"C:\\Program Files\\EmEditor\\EMEDITOR.EXE\" /p \"%1\""

Answer From Here.

So you should edit the registry on installation. Use Microsoft.Win32 Namespace To edit/add/remove Registry Keys.

Community
  • 1
  • 1
Danpe
  • 18,668
  • 21
  • 96
  • 131
  • thanks for the help !, but I did not understand - if i need that my program in (d:\OpenSDF.exe) will open all *.sdf files on my computer. what i need to change in this file ? – Gali Apr 21 '11 at 20:12
  • @Gali Look at this [Link](http://mel-green.com/2009/04/c-set-file-type-association/). Then use this code: ``if (!FileAssociation.IsAssociated(".sdf")) Associate(".sdf", "ClassID.ProgID", "sdf File", "YourIcon.ico", "D:\OpenSDF.exe");`` – Danpe Apr 21 '11 at 22:01
  • sorry, its work !!!, but how to deal if the .sdf was Associate to different program ? – Gali Apr 22 '11 at 05:54
  • and how i can change Associated file to new ? – Gali Apr 22 '11 at 12:34
  • Just use ``if (!FileAssociation.IsAssociated(".sdf")) Associate(".sdf", "ClassID.ProgID", "sdf File", "YourIcon.ico", "D:\DifferentProgram.exe");`` – Danpe Apr 24 '11 at 11:03