Start program by dragging file onto exe
-
Hi, Is it possible or how do you create a exe that when you drop a file onto it, the program will run and do a task on the file that your dragged onto it.
When you drag a file over an exe (or shortcut), the program will be started with the filename as a command line argument. You can either change Sub Main() to Sub Main(args() As String) or find some other way to get the command line arguments (System.Environment.GetCommandLineArgs(), for example). Something similar happens if you associate a file type with your program and double-click the file in explorer.
-
When you drag a file over an exe (or shortcut), the program will be started with the filename as a command line argument. You can either change Sub Main() to Sub Main(args() As String) or find some other way to get the command line arguments (System.Environment.GetCommandLineArgs(), for example). Something similar happens if you associate a file type with your program and double-click the file in explorer.
I will try explain what I am trying to do a little better than before. I have a program that when you run it the Open FIle Dialog appears so you can select a pdf to run a check on. What I want to do is to allow the user to drag and drop the pdf onto the exe an instead of opening the Open File dialog it would bypass it but still use the file name and path that I have selected as the file to check. An example of this would be if you create a text file on your desktop. You can then drag and drop the file on Notepad.exe and the file will open straight away.
modified on Thursday, July 3, 2008 10:46 AM
-
I will try explain what I am trying to do a little better than before. I have a program that when you run it the Open FIle Dialog appears so you can select a pdf to run a check on. What I want to do is to allow the user to drag and drop the pdf onto the exe an instead of opening the Open File dialog it would bypass it but still use the file name and path that I have selected as the file to check. An example of this would be if you create a text file on your desktop. You can then drag and drop the file on Notepad.exe and the file will open straight away.
modified on Thursday, July 3, 2008 10:46 AM
Gideon provided you with the answer you need When you drop a file onto you'r exe, the exe will start with in its arguments the path to that file like gideon said you can then eighter change the constructor of you'r startupform form public sub new() to public sub new(args() as string) or use System.Environment.GetCommandLineArgs() to get the arguments passed to the exe this is a standerd function in windows (drop any file onto (olmost) any exe and the exe will start) But all this has been said by Gideon so...
-
I will try explain what I am trying to do a little better than before. I have a program that when you run it the Open FIle Dialog appears so you can select a pdf to run a check on. What I want to do is to allow the user to drag and drop the pdf onto the exe an instead of opening the Open File dialog it would bypass it but still use the file name and path that I have selected as the file to check. An example of this would be if you create a text file on your desktop. You can then drag and drop the file on Notepad.exe and the file will open straight away.
modified on Thursday, July 3, 2008 10:46 AM
I haven't done that myself, but this article has a basic tutorial that should point you in the right direction. The main events here seem to be DragEnter and DragDrop.