Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Opening multiple files with my applicaton

95 views
Skip to first unread message

kimiraikkonen

unread,
Dec 25, 2007, 3:43:19 PM12/25/07
to
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.

JR

unread,
Dec 26, 2007, 2:47:47 AM12/26/07
to
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


"kimiraikkonen" <kimirai...@gmail.com> schreef in bericht
news:567d287b-fd3c-493e...@c4g2000hsg.googlegroups.com...

kimiraikkonen

unread,
Dec 26, 2007, 3:08:57 AM12/26/07
to
On Dec 26, 9:47 am, "JR" <xx....@xx.xx> wrote:
> 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
>
> "kimiraikkonen" <kimiraikkone...@gmail.com> schreef in berichtnews:567d287b-fd3c-493e...@c4g2000hsg.googlegroups.com...

>
> > 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.

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 ?

kimiraikkonen

unread,
Dec 26, 2007, 3:21:30 AM12/26/07
to

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

Family Tree Mike

unread,
Dec 26, 2007, 11:10:00 AM12/26/07
to

"kimiraikkonen" wrote:

> 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


kimiraikkonen

unread,
Dec 26, 2007, 11:45:45 AM12/26/07
to
On Dec 26, 6:10 pm, Family Tree Mike

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.

Family Tree Mike

unread,
Dec 26, 2007, 12:23:00 PM12/26/07
to
> 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.

kimiraikkonen

unread,
Dec 26, 2007, 1:01:53 PM12/26/07
to
On Dec 26, 7:23 pm, 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.

Family Tree Mike

unread,
Dec 26, 2007, 2:07:03 PM12/26/07
to
> 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.

kimiraikkonen

unread,
Dec 26, 2007, 2:21:06 PM12/26/07
to
On Dec 26, 9:07 pm, Family Tree Mike

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.

Teemu

unread,
Dec 26, 2007, 3:19:49 PM12/26/07
to

"kimiraikkonen" <kimirai...@gmail.com> kirjoitti viestissä
news:00e22bd3-1070-444d...@b40g2000prf.googlegroups.com...

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

Family Tree Mike

unread,
Dec 27, 2007, 7:00:01 AM12/27/07
to

"Teemu" wrote:

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.

kimiraikkonen

unread,
Dec 27, 2007, 10:31:48 AM12/27/07
to
On Dec 27, 2:00 pm, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.com> wrote:
> "Teemu" wrote:
>
> > "kimiraikkonen" <kimiraikkone...@gmail.com> kirjoitti viestissä

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.

kimiraikkonen

unread,
Dec 27, 2007, 11:12:06 AM12/27/07
to

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!

kimiraikkonen

unread,
Jan 4, 2008, 10:16:47 AM1/4/08
to
On Dec 27 2007, 2:00 pm, Family Tree Mike
<FamilyTreeM...@discussions.microsoft.com> wrote:
> "Teemu" wrote:
>
> > "kimiraikkonen" <kimiraikkone...@gmail.com> kirjoitti viestissä

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.

0 new messages