long filename argument in dotNet application

I am writing a dotNet application.  This application accepts argument in the Main function.  I want to be able to drag and drop a file onto this application.  When the file has a normal filename (ie without space), everything works fine.  When the file has a long filename with space, then I want the filename to be considered as one argument surrounded with double quotes (ie not 2 arguments when there is a space in the filename).

This dotNet application may have switches.

One example is when I create a *.bat file.  When I drag and drop another file onto this *.bat file, the %1 argument contains a filename surrounded by double quotes.

How can I achieve this in dotNet?
Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
There are several other ways...

(1) Event based approach:
Read the overview: http://msdn.microsoft.com/en-us/library/w3xx6ewx(VS.80).aspx
Startup() Event: http://msdn.microsoft.com/en-us/library/t4zch4d2(VS.80).aspx
StartupNextInstance() Event: http://msdn.microsoft.com/en-us/library/b9z4eyh8(VS.80).aspx
To use this approach the "Enable Application Framework" box must be CHECKED.  On that same tab, click on the "View Application Events" button in the bottom right to get the editor window.  Then change the two dropdowns across the top to get these events.  You can use "e.CommandLine" in either event to get the parameters.

(2) Accessing the parameters when YOU want them:
(a) My.Application.CommandLineArgs(): http://msdn.microsoft.com/en-us/library/z2d603cy(VS.80).aspx
(b) Environment.GetCommandLineArgs: http://msdn.microsoft.com/en-us/library/system.environment.getcommandlineargs(VS.80).aspx
(c)  Environment.CommandLine: http://msdn.microsoft.com/en-us/library/system.environment.commandline(VS.80).aspx
I'm not quite sure why there has to be a problem with long filenames, but you can declare a string and put the filename into. That way you can have as mush spaces as you'd like.
Guy2Author Commented:
As the application allow switches, some spaces are normal whereas some are within the long filename.  I want to distinguish between the two.  Moreover, in a drag and drop scenario, I do not know in advance the filename that will be used.
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Mike TomlinsonMiddle School Assistant TeacherCommented:
What version VB.net?...and is there a STRONG reason for starting with Sub Main()?
Guy2Author Commented:
VB.Net 2.0.

I understand that Sub Main is the only way we can get command line arguments.  Is there any other way?
Guy2Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.