Home >Backend Development >C++ >How to Associate Custom Executables with File Extensions in C#?
Associating custom executable files with file types in C#
Associate a specific file extension with a custom executable file in C#, allowing the user to launch the executable file with the associated file as a parameter when clicking the file in File Explorer. Additionally, you can specify the desired icon for the file extension.
Solution
Although .NET does not provide an API to directly manage file associations, you can utilize registry classes to manipulate necessary key values.
Example of registry file to associate .txt with EmEditor:
<code>[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\""</code>
The above is the detailed content of How to Associate Custom Executables with File Extensions in C#?. For more information, please follow other related articles on the PHP Chinese website!