I recently made a notepad like program for C# and found a library for using file associations. I am wondering how I would pass the path of the file double clicked in explorer, to a string so the file can read and 'open' the text file (like how notepad does). I have googled for a while, and asked around a few forums, and my friends. Any answers or nudges in the right direction are appreciated. Thank You
(note: I've already tried reading it from the string[] args
paramater in Main()
, which was suggested by someone else)
EDIT: Solved, it was the args[0]
. I was really tired when I started on this
This works fine for me!
public static void Main(string[] args){
if (args.Length == 0){
// Show your application usage or show an error box
return;
}
string file = args[0];
Application.Run(new MyProgram(file));
}
The suggestion was correct, the filename you double-click on in explorer will be visible in your app as an args parameter. Then you can do what you like with it, such as open a file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With