Click here to Skip to main content
15,889,863 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
hi all,

i have come across a problem, and i am not sure how to solve it Google is useless for this! (i use VB.net by the way and anything other than that right now will confuse me).

So i need to be able to double click on a file, this file opens the program and the program in turn opens the file.

now, the file association and the program opening a file is sorted, not an issue...but how can i get the directory of the file that is being used to open the program, after all it could be anywhere!

any input will be greatly accepted,

thanks for your time!

i finished the program but now (after I've published it to my server and then installed, when running as a default program it doesn't read the directory correctly using getcommandlineargs any more ideas?)

thanks again
Posted
Updated 16-Nov-13 4:40am
v2
Comments
Sergey Alexandrovich Kryukov 15-Nov-13 11:48am    
Not being able to read C# means getting very little help. Most of good materials on .NET is on C#. You just need to learn at least a bit of it.
—SA
Allw 18-Nov-13 4:05am    
I can read C# so get off the high horse...I choose to write in vb, because any other language confuses me when I have a lot of vb to code
Sergey Alexandrovich Kryukov 18-Nov-13 12:15pm    
I already knew that the rudest people are also most illiterate; and this correlation is quite strong, so thank you for giving me yet another evidence of it.
It's not acceptable to talk to people in this manner on this site.
—SA
Allw 19-Nov-13 8:40am    
And you think that people appreciate hijacking of questions in order to market your product?
Bernhard Hiller 18-Nov-13 4:00am    
" it doesn't read the directory correctly" - what does that mean? Does it show a different folder? None at all? Did you happen to remove the file association from the registry? ...?

The full path of the file that "opened" the program is available as the second (index 1) argument on the command line:

Environment.GetCommandLineArgs[^]

So the full path of the file is Environment.GetCommandLineArgs()(1)

(Index 0 is the executable name/path).
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 15-Nov-13 11:47am    
5ed.
—SA
Sergey Alexandrovich Kryukov 15-Nov-13 11:55am    
The real problem of OP is not command line, but also a problem with C#. I addressed both in my answer, Solution 2.
—SA
Please see my comment about VB.NET vs C#. Here is the good news: you can easily and automatically translate one into another with 100% accuracy. There are on-line and off-line/stand-along solutions, so, first of all, pay attention for the open-source stand-along tool, ILSpy, which can easily translate the whole project from C# to VB.NET and back. Please see my past answers:
Code Interpretation, C# to VB.NET[^].

Now, armed with all that, you can easily use C# projects as well. First, you can simply build available projects, references the assembly in your VB.NET project and just use in exact same was as it was in VB.NET. In this approach, you simply won't see any difference. And you also can translate, it you need it for better understanding.

That said, not you can use my work on command-line parameters, which is extremely easy to use (and one more, more complicated, is recommended in my article): Enumeration-based Command Line Utility[^].

Good luck,
—SA
 
Share this answer
 
Comments
Ron Beyer 15-Nov-13 11:58am    
5'd, I always hate working with command line directly and usually use some kind of parsing tool to make life easier.
Sergey Alexandrovich Kryukov 15-Nov-13 12:07pm    
Sure. My parsing tool is quit unusual (in ease-of-use, too, not string specifications, ever) and is the illustration of the whole technique which makes enum really enumerate (did you ever wonder why enum types don't support IEnumerable?).
Thank you, Ron.
—SA

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