opening a file with my program on double click

E

EricW

Hi,

I would like to know how I can make my program to open the file I double
clicked on in a folder.

So I've associated the file with the program, but when I double click on it,
it starts the program, but the file is not opened with it.

how can i program this?

tia,
Eric
 
K

kimiraikkonen

Hi,

I would like to know how I can make my program to open the file I double
clicked on in a folder.

So I've associated the file with the program, but when I double click on it,
it starts the program, but the file is not opened with it.

how can i program this?

tia,
Eric

Eric,
You need to pass command line arguments of your programs in form_load
event. I don't know what your application does but here is a sample
that you can open a text file "with" a VB.NET app:

For example, open a text file with streamReader:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then

myStreamReader = System.IO.File.OpenText(cla(1))
TextBox1.Text = myStreamReader.ReadToEnd
myStreamReader.Dispose()


----------------

It's optional and depends on your application to select which command
argument you want to get, sampled as cla(1) above.

Hope this helps, let me know.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
 
E

EricW

thanks for the info!

rg,
Eric

"kimiraikkonen" <[email protected]> schreef in bericht
Hi,

I would like to know how I can make my program to open the file I double
clicked on in a folder.

So I've associated the file with the program, but when I double click on
it,
it starts the program, but the file is not opened with it.

how can i program this?

tia,
Eric

Eric,
You need to pass command line arguments of your programs in form_load
event. I don't know what your application does but here is a sample
that you can open a text file "with" a VB.NET app:

For example, open a text file with streamReader:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then

myStreamReader = System.IO.File.OpenText(cla(1))
TextBox1.Text = myStreamReader.ReadToEnd
myStreamReader.Dispose()


----------------

It's optional and depends on your application to select which command
argument you want to get, sampled as cla(1) above.

Hope this helps, let me know.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
 
E

EricW

It worked fine! thanks again!

"kimiraikkonen" <[email protected]> schreef in bericht
Hi,

I would like to know how I can make my program to open the file I double
clicked on in a folder.

So I've associated the file with the program, but when I double click on
it,
it starts the program, but the file is not opened with it.

how can i program this?

tia,
Eric

Eric,
You need to pass command line arguments of your programs in form_load
event. I don't know what your application does but here is a sample
that you can open a text file "with" a VB.NET app:

For example, open a text file with streamReader:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then

myStreamReader = System.IO.File.OpenText(cla(1))
TextBox1.Text = myStreamReader.ReadToEnd
myStreamReader.Dispose()


----------------

It's optional and depends on your application to select which command
argument you want to get, sampled as cla(1) above.

Hope this helps, let me know.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
 
K

kimiraikkonen

It worked fine! thanks again!

"kimiraikkonen" <[email protected]> schreef in bericht





Eric,
You need to pass command line arguments of your programs in form_load
event. I don't know what your application does but here is a sample
that you can open a text file "with" a VB.NET app:

For example, open a text file with streamReader:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load
Dim cla As String() = Environment.GetCommandLineArgs()
If cla.Length > 1 Then

myStreamReader = System.IO.File.OpenText(cla(1))
TextBox1.Text = myStreamReader.ReadToEnd
myStreamReader.Dispose()

----------------

It's optional and depends on your application to select which command
argument you want to get, sampled as cla(1) above.

Hope this helps, let me know.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles MyBase.Load

You're welcome :)
 

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