So I searched for a guide of how to shell integrate your application (add it to the right click menu) with C#, but I couldn't find how to do that only for a specific file type. I know it is possible because WinRar does that. So how can I do that?
There are usually two-ish ways you can implement this.
Registry Keys - You can write keys and values under HKEY_CLASSES_ROOT. If you look at that hive you'll see the extensions on your pc. Look at this article for the details about the keys and values. Something simple like an option to open .myfile
types with your application is possible here. Here is a File Association Example
Shell Extensions (Written in COM) : Here you can do more complicated stuff like Handlers. They will get called by Windows so you can do things like paint on menus, or add custom actions when a file is right-clicked. There is more to it here than files, you can even add property sheets and custom tooltips.
You will find some talk about not using .NET to write a Shell Handler**. This applies only to older versions of .NET. Its all ok with .NET4.
This article should help you with a Context Menu Handler in .NET4
** Why was it not recommend:
When you write a shell handler, it gets called by the host process (typically windows explorer), but also things like FileOpenDialogs and FolderBrowser dialogs. So a problem would occur if you wrote a shell extension in .NET 2.0, and a .NET 1.1 app called a File Open Dialog and then your .NET 2.0 shell handler would be called into and your .NET 1.1 app which has an older CLR and there would be version conflict.
So I'm pleased to have found out finally this has been fixed somehow in .NET 4 =)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With