Set default html editing program

ADO DOT NET

Centurion
Joined
Dec 20, 2006
Messages
160
Hi
I have written a .net html editor and want to check in form_load if it is the default html editor. how should I do it via .net 2?
also how can I add an item to the context menu of windows explorer named "edit with my html editor"?
thanks.
 
The only way I know of doing this is via the registry;

If you look under the HKEY_CLASSES_ROOT key you should see an entry for .html - this will have as it's default value something like htmlfile. If you then look under HKEY_CLASSES_ROOT\htmlfile\shell\edit\command then you will see the currently registered application.

To make your application the default simply change this to point to your app (this is pretty easy to do via the registry classes under .Net)

Personally I would make this an option within your program rather than resetting it every time your application is run as the user might prefer another tool and choose your application for a feature that it excels in - if running the app causes it to take over the association I would soon stop using it.
 
Thanks, it was great!
Just one problem:
I use this code to get data from registry:
Visual Basic:
My.Computer.Registry.ClassesRoot.OpenSubKey("htmlfile\shell\Edit\command").GetValue("").ToString
But when I use this code to save data to registry:
Visual Basic:
        Dim MyKey As RegistryKey = Registry.CurrentUser.OpenSubKey("htmlfile\shell\Edit\command")
        MyKey.SetValue("", My.Application.Info.DirectoryPath + "\MyEditor.exe")
I get error: Object reference not set to an instance of an object.
Please see attachment, it does not have a name! What should I do? :confused:
 

Attachments

You are getting the error because you are opening the CurrentUser hive instead of ClassesRoot when you are saving the setting. If a key does not exist then a null reference is returned instead of an exception being thrown.

Also, not only should you make this an option, but don't be surprised if an exception is thrown when the code is run on a limited user account.
 
Back
Top