Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I've associated my vb.net program with a file extension so that if one of the files my program uses is double clicked it will open the program.

I need to know the name of the file that was clicked.

I'm sure there's a really easy way to do this, I just don't know what it is. I would appreciate it if someone could tell me.

Thanks
Posted
Comments
Homero Rivera 6-Dec-14 23:12pm    
So, if you double-click the file you want your program to launch and read your associated file?
I think you need to add something on Windows upon your program installation so it recognizes that.
Member 11291420 6-Dec-14 23:52pm    
Yes, I've already set up the association between my file extension and my program on the users machine in the installation.msi process. My problem is I need my program to know the file name so that it can process that file. For example if it were a text document it would open the program and display that particular document. I'm thinking there should be a way to get something like a command line argument.
Homero Rivera 6-Dec-14 23:17pm    
It's a start, but it makes sense that you need to go deeper down to libraries beyond .net. Good luck. https://social.msdn.microsoft.com/Forums/en-US/a3fbf149-c373-4bbf-b7bd-6c6ccfbcf9df/how-to-i-create-my-own-file-extention-espcially-for-my-own-softwere-?forum=csharpgeneral
Member 11291420 6-Dec-14 23:54pm    
Thanks for that, but I've already got the extension organised and associated with my program, it's a matter of getting the name and path of the file so that I can process it.
Homero Rivera 7-Dec-14 0:15am    
static void Main(String[] args){ /* try fetching the filename from "args" */ }

Only suggesting...

There is a whole bunch of stuff under My.Application and My.Application.Info. You should be able to find it there, but off the top of my head, I cannot remember exactly where.
 
Share this answer
 
Homero Rivera used a C# example but the principle still stands...You can declare your Main function with arguments (parameters) e.g.
VB
Module Module1
    Sub Main(ByVal CmdArgs() As String)
        For Each s As String In CmdArgs
            Console.WriteLine(s)
        Next
        Console.ReadKey()
    End Sub
End Module

If you declare the Main function without arguments then you can still access the command line arguments as per the link provided by Peter_in_2780 e.g.
Module Module1
    Sub Main()
        For Each t As String In My.Application.CommandLineArgs
            Console.WriteLine(t)
        Next
        Console.ReadKey()
    End Sub
End Module
In addition to making a file extension association as you have done, you can also drop files onto the executable for the same effect, or copy your executable into (e.g.) C:\Users\Default\AppData\Roaming\Microsoft\Windows\SendTo so it will appear in the context menu when you right-click on a file in Explorer
 
Share this answer
 
Comments
Member 11291420 7-Dec-14 17:14pm    
Thanks everyone, my Main doesn't accept arguments however My.Application.CommandLineArgs works a treat. I appreciate the assistance you all provided.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900