How do I associate a File Extension with my application?
Locked
-
Friday, April 10, 2009 9:01 AM
How do I associate a File Extension with my application?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
All Replies
-
Friday, April 10, 2009 9:01 AM
All the file type-app associations are stored in the Registry. To create a file extension associated with your application, you need to write a Registry Key to register it.
For example: Creating a file extension named .Hello.
My.Computer.Registry.ClassesRoot.CreateSubKey(".Hello").SetValue("", _ "Hello", Microsoft.Win32.RegistryValueKind.String) My.Computer.Registry.ClassesRoot.CreateSubKey("Hello\shell\open\command").SetValue("", _ Application.ExecutablePath & " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
Explanation to above code sample:Code
What it does
CreateSubKey(".Hello")
Creates a registry key in ClassesRoot for the .Hello extension. Notice that you must include the beginning period.
.SetValue("", "Hello"...
1. "" (Or Nothing) sets the default value of the key.
2. "Hello" is like the "txtfile" we saw earlier; it tells which registry key contains the information about the .Hello extension.
CreateSubKey("Hello" & _ "\shell\open\command")
This creates the "Hello" sub-key and the "store\open\command" subkey that is needed to store the path to the application that will open this file type.
.SetValue("", Application.ExecutablePath & _ " ""%l"" ",...
1. Again, "" tells the application to set the key's default value.
2. Application.ExecutablePath tells the code to associate the currently running executable
with this file type.3. " ""%1"" " passes the opened file's location to your program. The quotes around it are
optional, but if you have more than one argument, you must put them around each.Detailed walkthrough and demo project can be found here:
http://www.codeproject.com/useritems/VBFileAssociation.asp
Additionally, you can manually create a file extension via Windows Explorer:
Tools menu -> Folder Options -> File Types -> Create New Extension by specifying File Extension and Associated File Type.
Related thread:
http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/4d8760c9-b2c9-4016-b75e-1b3189b0c30b/
For more FAQ about Visual Basic .NET General, please see Visual Basic .NET General FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer by Xiaoyun Li – MSFT Friday, April 10, 2009 9:02 AM

