ComServerAssociation

Feb 20, 2013 at 4:54 PM
Hi,

I'm trying to use SharpShell, but when I add [ComServerAssocition(...)] VS could find the object and ask for a namespace or assembly. SharpShell is added as reference in the project.

Thanks,
Yannick
Coordinator
Feb 21, 2013 at 7:36 AM
Hi,

The original code used:

ComServerAssocition

which has a spelling mistake - (a missing 'a' after the last 'c'). Please use the spelling below:

ComServerAssociation

and it will work :)
Feb 21, 2013 at 8:20 AM
Edited Feb 21, 2013 at 8:21 AM
ok, it's perfect.
I've see you example for Association Attribute. I want to associate a Context Menu on a specific Directory.
Is it possible if I do :
[COMServerAssociation(AssociationType.Directory, @"c:\users")]
Thanks,
Yannick
Feb 21, 2013 at 6:43 PM
I need to know also if is it possible to manage association by code. for example, to read registry or a config file ...
Thanks,
Yannick
Coordinator
Feb 21, 2013 at 9:02 PM
For the directory, this is not possible - what you must do is set the COM Server Association on directories, and then in the CanShowMenu function return false unless the directory (which is stored in the SelectedItemPath variable) is "c:\users" - this is the only way to register a shell extension for a directory and have it used for only one specific directory.

To set an association by code is fine - just do not use a COM Server Association at all, just the ServerRegistrationManager object - you can pass that the server you want to register and the association you want to make. Just be careful to delete the OLD associations before adding new ones, to keep the end users's registry clean and tidy.