Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

long filename argument in dotNet application

Posted on 2009-05-19
6
Medium Priority
?
393 Views
Last Modified: 2013-11-25
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?
0
Comment
Question by:Guy2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 5

Expert Comment

by:karstieman
ID: 24426751
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.
0
 

Author Comment

by:Guy2
ID: 24426767
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.
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 24427321
What version VB.net?...and is there a STRONG reason for starting with Sub Main()?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:Guy2
ID: 24429343
VB.Net 2.0.

I understand that Sub Main is the only way we can get command line arguments.  Is there any other way?
0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 24432470
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
0
 

Author Closing Comment

by:Guy2
ID: 31583239
Good!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question