[2005] Open your program by opening a file
Well this is my question:
With my program i created a file. Example: file.myE(xtention)
Now ill tell windows that all the *.myE must be opend by my own programm: iOpenYou.exe.
How do i tell in my program wich method i must call when windows is sending that file to my .exe? I know that in Java it is the contructor Main(args[] as string) and you can extract the filename from args[].
But can i do this in VB.net?
Greets
Re: [2005] Open your program by opening a file
You will want to create a File Association. This is when you associate a file extension with a default program. So when you double click a file with that extension it will open with the specified program.
Re: [2005] Open your program by opening a file
Yes thats correct :D and how i must program what to do with the file.
Like is there a standard method called OpenWhenProgStarts(filename as string) or something? What i must do in my code to use that file(i know how to work with streams(readers/writers) etc. (or with more file names)
Re: [2005] Open your program by opening a file
what type of file is it?
what would you do with the file if you opened it from within the program, instead of the program being started because you've chose to run the file?
it is possible to use the main sub with args in vb.net
Re: [2005] Open your program by opening a file
You would do it with the File Types editor in your setup project for deployment.
http://msdn2.microsoft.com/en-us/lib...k6(VS.80).aspx
Re: [2005] Open your program by opening a file
Quote:
Originally Posted by .paul.
what type of file is it?
what would you do with the file if you opened it from within the program, instead of the program being started because you've chose to run the file?
it is possible to use the main sub with args in vb.net
I would do exactly the same when i open the file inside my program.
And it doesnt matter what file type it is. I just want to know how to do it, even when its just plain text shown in a message box and after that close the program when i open that file.
How to use this Main sub with args[] in vb.net?
Greets
Re: [2005] Open your program by opening a file
Using the Args in the Main wont make it so that when you double click on your file extension it will open in your app. ;)
Re: [2005] Open your program by opening a file
Re: [2005] Open your program by opening a file
See the link I posted in #5. ;)
Re: [2005] Open your program by opening a file
Quote:
Originally Posted by RobDog888
See the link I posted in #5. ;)
what about for debugging + testing it?
Re: [2005] Open your program by opening a file
For testing you should use Virtual PC 2007. Then you can install / uninstall til the cows come home without affecting your system install.
To view your settings for file types just click (within the Setup project) View > File Types
Re: [2005] Open your program by opening a file
Well doeing it with a setup project is an other story.
On that link you gave me there is no sample code or module i need to reference to or something like that.
All i need to know is what code i need to write within my project to do this.
Ill ask my question in an other way then:
I have a file called: my.msgbox and an .exe called show.exe.
When i drag my.msgbox to my show.exe which method i need to implement or what code i need to show the the text(that is inside my.msgbox) in a message box.
Deploying with a setup will be the next step but first i want to know this.
(Maybe it can be found on that link but i cant)
Greets
Re: [2005] Open your program by opening a file
Ok i found it.
It was very simple ^^.
vb Code:
Public Module File_assosiation ' (this is your exe name)
Public Sub Main(ByVal args() As String)
If args.Length > 0 Then
MsgBox(args(0))
Else
MsgBox("no file")
'System.Diagnostics.Process.Start(args(0))
End If
End Sub
End Module
So thnx for helo anyway :D
Greets
Re: [2005] Open your program by opening a file
Quote:
Originally Posted by ovanwijk
Ok i found it.
It was very simple ^^.
vb Code:
Public Module File_assosiation ' (this is your exe name)
Public Sub Main(ByVal args() As String)
If args.Length > 0 Then
MsgBox(args(0))
Else
MsgBox("no file")
'System.Diagnostics.Process.Start(args(0))
End If
End Sub
End Module
So thnx for helo anyway :D
Greets
You can forget all that, use this:
Code:
Dim Args() As String = Environment.GetCommandLineArgs
For Each Arg As String In Args
'I usually use a SELECT CASE here, forcing Arg to be all lower case
Next Arg
This code can be used anywhere in the project, even the Load event of your startup form, this way you don't have to use a Sub Main, if you don't want to