I created a filetype of my own (.track), and was able to set the association in the publish options of my solution. After installing my program, double clicking on any .track file opens up my application. When this happens, I want the program to load the contents of the file that has been double clicked.
public static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if(args.Length == 1)
{
MessageBox.Show(args[0]); //For Debugging
Application.Run(new TrackerForm(args[0]));
}
else
{
MessageBox.Show(args.Length.ToString()); //Confirms that no arguments are passed.
Application.Run(new TrackerForm());
}
}
I assumed that the path of the double clicked file would be passed to the application via a command line argument. However, double clicking on a file of my associated filetype passes no arguments at all to my executable. What exactly happens when a file of an associated executable is double clicked? What do I need to do to allow my program to load a file that is double clicked in windows explorer?
When I debug using a filepath as a command line argument, my program functions perfectly, so I do not think it is due to an error opening files.
When you double click a file the shell launches it using the "Open" Verb. The "Open" verb runs the application as follows:
"My Program.exe" "%1"
"%1" is the path of the file you double clicked on. You can check out this MDSN page for more info.