Keanu Lorenzo Keanu Lorenzo - 2 months ago 11
Vb.net Question

Make custom file open by a custom program VB

How to make a file (

.jkl
extension for example) that when you open it, your custom program will pop-up.

For example:

I have a
test.jkl
file

If i double-click it, my program will be the one to read it.

Just like a .jpg file extension, when double-clicking the file, paint will pop-up and shows the image.

My code when changing the file ext is just simple

File.Copy(origFile, origFile.Replace("txt", "jkl")
File.Delete(origFile)


So now i have a
.jkl
file, now what I need to do is when the user double clicks the
.jkl
file, this program will automatically open, ask where to save it, and change it back to
.txt
to the path where the user wants to.

How can I do this?

Answer

Put it the form load event. it will write again and again. It won't destroy your PC. If you want to more carefully. Read registry check if it is exist then skip write again.

Code:

My.Computer.Registry.ClassesRoot.CreateSubKey(".jkl").SetValue_
    ("", "jkl", Microsoft.Win32.RegistryValueKind.String)
My.Computer.Registry.ClassesRoot.CreateSubKey_
    ("jkl\shell\open\command").SetValue("", Application.ExecutablePath & _
    " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)

link for demo project: http://www.codeproject.com/Articles/18594/File-Association-in-VB-NET