Opening multiple files with my applicaton

K

kimiraikkonen

Hi,
I have an app which has a listbox and when i double click an
associated fileS, i want their paths to be added into listbox in my
application.

This code works good when i try to open a "single" file with my app
which works to get commandline arguments to get file paths:

Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then
ListBox1.Items.Add(cla(1))
End if

But this doesn't work while opening more than one files at the same
time.

Assume i select 3 files with pressing CTRL + left mouse and then "open
with" my application, then i want these three files' paths must be
added as items into the listbox. (listbox will have 3 items, items are
the paths of files)

I hope you can help.

Regards.
 
J

JR

try the following
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length >= 1 Then
If cla.Length = 1 Then
ListBox1.Items.Add(cla(1))
else
for n as integer=2 to cla.length
ListBox1.Items.Add(cla(1) & iif(cla(1).endswith("\"),"","\") &
cla(n))
next
End if

when there is more than 1 file the first item is the folder the others are
the name
so check if 1 take one complete
if more take one and add the names

if the files are in the root the folder has already a backslash therefore
check also with: iif(cla(1).endswith("\"),"","\")


Jan
 
K

kimiraikkonen

try the following
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length >= 1 Then
If cla.Length = 1 Then
ListBox1.Items.Add(cla(1))
else
for n as integer=2 to cla.length
ListBox1.Items.Add(cla(1) & iif(cla(1).endswith("\"),"","\") &
cla(n))
next
End if

when there is more than 1 file the first item is the folder the others are
the name
so check if 1 take one complete
if more take one and add the names

if the files are in the root the folder has already a backslash therefore
check also with: iif(cla(1).endswith("\"),"","\")

Jan

JR,

Tried the code you've given but it doesn't work. If i modify as
"cla>=1" i get "index outside of bounds" error, if i "cla>1" no error
but no multiple files' paths added to my listbox.

What's the correct coding to add multiple files' paths into listbox
when i open tem with application ?
 
K

kimiraikkonen

JR,

Tried the code you've given but it doesn't work. If i modify as
"cla>=1" i get "index outside of bounds" error, if i "cla>1" no error
but no multiple files' paths added to my listbox.

What's the correct coding to add multiple files' paths into listbox
when i open tem with application ?

Note: Multiple files are selected in the same folder as normal.
 
F

Family Tree Mike

kimiraikkonen said:
Hi,
I have an app which has a listbox and when i double click an
associated fileS, i want their paths to be added into listbox in my
application.

This code works good when i try to open a "single" file with my app
which works to get commandline arguments to get file paths:

Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then
ListBox1.Items.Add(cla(1))
End if

But this doesn't work while opening more than one files at the same
time.

You are only adding the first item from the command line. Change your code
to:

Dim cla As String() = Environment.GetCommandLineArgs()
Dim idx as Integer

If cla.Length > 1 Then
for idx = 1 to (cla.Length-1)
ListBox1.Items.Add(cla(idx))
next idx
endif
 
K

kimiraikkonen

You are only adding the first item from the command line. Change your code
to:

Dim cla As String() = Environment.GetCommandLineArgs()
Dim idx as Integer

If cla.Length > 1 Then
for idx = 1 to (cla.Length-1)
ListBox1.Items.Add(cla(idx))
next idx
endif

Hi Family Tree Mike,
Tried your code but only one file's path is added into listbox when i
try to open more than one file "with" my app by selecting CTRL + mouse
left click.

The thing i want to implement is exactly like when you select more
than one files, then "open with" Windows Media Player, then these
files are added into playlist of WMP. The same strategy i want to see
worked.(I only want to add paths of fileS).

Thanks.
 
F

Family Tree Mike

The thing i want to implement is exactly like when you select more
than one files, then "open with" Windows Media Player, then these
files are added into playlist of WMP. The same strategy i want to see
worked.(I only want to add paths of fileS).

Thanks.

I hate to say this, but Windows Media Player behaves in the same way for me
when using "Open with Windows Media Player". It behaves as you want when
selecting "Play with Media Player". I am unsure how the modes are different
when starting from Explorer.
 
K

kimiraikkonen

I hate to say this, but Windows Media Player behaves in the same way for me
when using "Open with Windows Media Player". It behaves as you want when
selecting "Play with Media Player". I am unsure how the modes are different
when starting from Explorer.

Hi Mike,
If i use "open with" method after selecting multiple files, you're
right that WMP adds only one file to its playlist. If i use "Play with
Media Player" method, all the selected multiple files are added into
playlist. This is also the same in WinAMP.

So maybe i need to add a root context menu(not submenu like "open
with" when you right click) in order to manipulate the same thing like
"Play With Media Player"

What do you recommend for doing this?

Thanks for your support.
 
F

Family Tree Mike

Hi Mike,
If i use "open with" method after selecting multiple files, you're
right that WMP adds only one file to its playlist. If i use "Play with
Media Player" method, all the selected multiple files are added into
playlist. This is also the same in WinAMP.

So maybe i need to add a root context menu(not submenu like "open
with" when you right click) in order to manipulate the same thing like
"Play With Media Player"

What do you recommend for doing this?

Thanks for your support.

I'm unsure about what is best, but you might try the following. I created a
shortcut to my application and placed the shortcut into the users "Send To"
folder. This adds the application to the list of apps that accept a "Send
To" request. When I did this with multiple files, my app recognized them all
and acted appropriately. The user's "Send To" folder is normally hidden, but
it is under the users folder, just like "My Documents" is. Hope this helps.
 
K

kimiraikkonen

I'm unsure about what is best, but you might try the following. I created a
shortcut to my application and placed the shortcut into the users "Send To"
folder. This adds the application to the list of apps that accept a "Send
To" request. When I did this with multiple files, my app recognized them all
and acted appropriately. The user's "Send To" folder is normally hidden, but
it is under the users folder, just like "My Documents" is. Hope this helps.

Hi Mike,
You're completely right, send to method also worked with me with the
code you've given. But i hope we could find another context menu
association parameter that behaves like "play with media player" for
Windows Media Player or "enqueue in Winamp" for WinAmp.

Thank you.
 
T

Teemu

"kimiraikkonen" <[email protected]> kirjoitti viestissä

Replace %1 with %L from registry and see what kind of parameters you get.
Also try to change your application to single instance mode from project's
properties.

-Teemu
 
F

Family Tree Mike

Teemu said:
"kimiraikkonen" <[email protected]> kirjoitti viestissä

Replace %1 with %L from registry and see what kind of parameters you get.
Also try to change your application to single instance mode from project's
properties.

-Teemu

Changing the test application to single instance mode, for me, had no effect
but it seemed like a logical thought. What registry entry are you talking
about changing the %1 to %L? I wasn't working in the registry.
 
K

kimiraikkonen

Changing the test application to single instance mode, for me, had no effect
but it seemed like a logical thought. What registry entry are you talking
about changing the %1 to %L? I wasn't working in the registry.

I haven't tried but maybe you can take a look at Winamp's "Play in
Winamp" action in tools->folder options-> "file types" for mp3
extension -> advanced -> edit section.
It used "%1" parameter separately. But this is not enough because you
have to integrate this parameter "same thing" during the installation
of your software via installers or manually.
 
K

kimiraikkonen

I haven't tried but maybe you can take a look at Winamp's "Play in
Winamp" action in tools->folder options-> "file types" for mp3
extension -> advanced -> edit section.
It used "%1" parameter separately. But this is not enough because you
have to integrate this parameter "same thing" during the installation
of your software via installers or manually.

Also if i modify a file type's parameters (eg: mp3) to following and
try to open for example 3 files at the same time, i get three seperate
app windows. 3 different app windows for 3 files. I wish they were
added into a single app window's listbox.

"C:\Documents and Settings\Kimi\My Documents\myapp.exe" "%1" which
didn't help.

My current form_load code is this which work fine with "send to"
method as Family Tree Mike suggested but no chance with main context
menu like "Play With Media Player" which adds all selected items into
its listbox.

Dim cla As String() = Environment.GetCommandLineArgs()
Dim idx As Integer
If cla.Length > 1 Then
For idx = 1 To (cla.Length - 1)
ListBox1.Items.Add(cla(idx))
Next idx
End If

Thanks!
 
K

kimiraikkonen

Changing the test application to single instance mode, for me, had no effect
but it seemed like a logical thought. What registry entry are you talking
about changing the %1 to %L? I wasn't working in the registry.

Hi again, does somebody know how to open "multiple files" with my app
using "open with" located in first context menu?
The code Family Tree Mike suggested works fine with "send to" method,
but "open with" doesn't work and only opens a single file with my
app(adding files' paths into my app's listbox), as Teemu stated we
must add %1 or L parameter entries.

How to do that and has somebody accomplished this?

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top