I'm an amateur at c# and I've been unable to locate the answer to this. Perhaps I am not aware of the correct terms to use.
When a video file is dragged onto my exe application, I would like the application to know that it was launched with a file and be able to know the path and filename of that file. This way, the user does not have to use the file>open menu.
Hope that makes sense. Thanks
You can check the command line arguments which were used to launch the application. If your application was started by dropping a file on the .exe file, there will be a single command line argument with the path of the file.
As your question title states, you want the path and the file name. You can get the file name using:
You need your application's command-line arguments. When you drop a file on your application in Explorer, Explorer opens the application with the file you dropped on it. You can select as many files as you want, drop them on your application and using this line of code,
files
will be an array of those command line arguments.When you drag a file into a C# application, it will goes as an command-line argument to that application. Like console applications, you can catch it on the Main method on the Program class.
I'll explain it using Windows Forms application.
Open your Program class on the solution. Your program class should look like this.
By default, when you create Windows Forms applications, they don't treat command line arguments. You have to make a tiny change on the signature of the Main method, so it can receive arguments:
Now you can handle file name argument passed to the application. By default, Windows will put the file name as the first argument. Just do something like this:
In case you want to know the constructor overload of my Form1, here it is. Hope it helps!