How do I launch vb app with a file drag over

  • Thread starter Thread starter Paul
  • Start date Start date
P

Paul

I have looked and looked for this info. All the I/O
examples I've found either explicity use a file name or use
the OpenFileDialog. When you drag a MS Word document over
MS Word, it launches and opens the document. I would like
my App to launch and open a document (if it has the correct
extension). What is the launch event sequence and where do
I pick up the path/name of the file or files that were
dropped on the application icon?

Any advice or link to info about this is appreciated.

Thanks.

Paul
 
IIRC, when you drop a file on an icon windows will start the application
passing the path to the dropped file as a parameter.


HTH
Brian W
 
Yes, I figured it would launch the program and execute the
code I have in Sub Main. The question is, what parameter
contains the path/name of the file? I'm assuming it would
/could be an array of path names because a person can
select several files and drop them on at once - or
possibly a folder of files.

In this specific case, I don't even need to open a form -
Just read the dropped file, reformat the data a bit and
write it back out to the same location (path) with the same
name and a different extension. If mulitple files are
dropped I could create an output file for each or combine
the data in all of them to one output file.

So - what parameter do I look at?
Thanks,

Paul
 
What do you mean what parameter?

It's not really that difficult, take a look at command$

try the following code:

Sub Main()
Dim s As String = Command$()
Console.WriteLine(s)
Console.ReadLine()
End Sub

Drop 1 to N files on the compiled .EXE, you will find something like this:

The file names will be quoted and space delimited.


Regards
Brian W
 
Brian,
Thank you for your example. You previously posted the file
names would be passed as a parameter (...when you drop a
file on an icon windows will start the application passing
the path to the dropped file as a parameter.) so I was
asking what parameter that would be. It looks like the
dropped path/file names are put into s by the Dim s As
String = Command$() line. So I'll research Command$().
Thanks for pointing me in the right direction.
Paul
 
Brian,
Thank you for your example. You previously posted the file
names would be passed as a parameter (...when you drop a
file on an icon windows will start the application passing
the path to the dropped file as a parameter.) so I was
asking what parameter that would be. It looks like the
dropped path/file names are put into s by the Dim s As
String = Command$() line. So I'll research Command$().
Thanks for pointing me in the right direction.
Paul

You can also declare you sub main thusly:

Sub Main(sArgs() As String)

End Sub


The the sArgs array would contain all the command line parameters.

Also look as Environment.CommandLine
 
snip

You can also declare you sub main thusly:

Sub Main(sArgs() As String)

End Sub

Chris,

Are you saying that in that syntax, sArgs() will already
contain the string for file name/s or will I still need to
put them in there via sArgs = Command$()

I'm sorry to be such a newbie at this - I've worked with
VB6 and other Basics before but I seem to be having a hard
time finding the info I need for vb.net.

It looks like you no longer compile to an .exe. Instead you
do a Build, then run an Install/Deploy wizard to combine
all the parts to an .exe

That makes testing this situation a little ackward as I
can't drop a file on till I get to that .exe

Paul
 
No, you do not assign sArgs=Command$()

Each element in the sArgs array will be a parameter.

In other words, assume you drop the following files onto your EXE:

file1.txt file2.txt file3.txt

you can then loop through the array like this

Dim s As String
for each s in sArgs
DoSomething(s) ' Do something with the file.
next

This is actually easier than VB 6 or below, there it was up to you to parse
the command line, here most of the work is done for you.

I'm sorry to be such a newbie at this - I've worked with
VB6 and other Basics before but I seem to be having a hard
time finding the info I need for vb.net.

There is plenty of info out there, just pick a topic and Google it.
It looks like you no longer compile to an .exe. Instead you
do a Build, then run an Install/Deploy wizard to combine
all the parts to an .exe

Where did you get that idea? And is simple untrue. Your compiled application
will be in the Bin directory under your solution directory.

If your solution contains other projects referenced by your main EXE project
(Class libraries, Control libraries etc) they will be in the Bin directory
as well.



Regards
Brian W
 
Back
Top