Say, you have developed web based File Management System (FMS), where users can upload files. Your FMS will catalog all files and allow users to search & group uploaded files. If I am a user of such FMS, what I would like that I can right click on any file in windows explorer where it shows me menu item for sending file to FMS.
Say, you have built encryption application which can encrypt any file or file folder. Again, I would like if you do some magic to allow me to specify file/folder to be encrypted in context menu of windows explorer.
Say, you have created a command line tool, which does something with objects appearing in windows explorepr (files, folders, drives, network shares etc). If you can provide context menu item for your command line tool, your users will be happy - as they will not need to traverse folders at command line. Check this.
There are two ways of doing things. Easy way and toguh way. (sorry, if you do not like such openings :))
Let us see.
Tough way: Windows explorer knows COM. If you implement some interfaces like IContextMenu in a COM dll and then you register your dll with Windows registry in a way explorer understands, then you can make context menu do anything you want. The problem is you do not know COM! Bigger problem is explorer does not know .NET CLR yet! That translates that you do not want to do not want to be burderned with complex things ;-) Go here to know more.
Easy way: Windows explorer knows registry. you know C#. And .NET knows Registry. Whenever you rightclick in explorer, it looks into registry at a location to find custom context menu items (thanks to MS engineers, who forethought). If it finds one, then it displays it. If you choose that item, filepath is passed as command line parameter to specified exe.
I have gone easy way, and have created a simple class for you which will allow you to customize context menu programatically. As a proof of concept, I have created a small winforms project which will allow your to cusotmize context menu manually.
Using the code
Class is called
Constructor accets Unique name which will be used to name registry key.
private ShellContextMenu m_scm = new ShellContextMenu("Newtonica.Utility.ContextMenu");
You simply then call public methods of instance to add, read or remove context menu items.
m_scm.SetContextMenuItem(ShellContextMenu.ContextMenuFor.ALLFILES,"Send to FMS...", "MyFMS.exe %1%", "");
To understand it clearly, go through source code.
If you compliel exe, here is how it will look. (and work hopefully, too.). As I do not have FMS.exe, I have taken notepad.exe as place holder.
Points of Interest
1. To have complete flexibility, you need to implement COM interfaces tough way, and it is worth it.
2. If simple way is enough for the purpose, do not overkill. <comment title="----------------------------- That's it! -------------------------" xmlns="http://disruptive-innovations.com/zoo/nvu">
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.