ADO DOT NET Posted November 22, 2007 Posted November 22, 2007 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. Quote
Administrators PlausiblyDamp Posted November 25, 2007 Administrators Posted November 25, 2007 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
ADO DOT NET Posted November 26, 2007 Author Posted November 26, 2007 Thanks, it was great! Just one problem: I use this code to get data from registry: My.Computer.Registry.ClassesRoot.OpenSubKey("htmlfile\shell\Edit\command").GetValue("").ToString But when I use this code to save data to registry: 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: Quote
Leaders snarfblam Posted November 26, 2007 Leaders Posted November 26, 2007 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.