-1

I'm sure I am overlooking something, or not searching for the right question-

I have an application that saves a project file (it's in XML) but the file extension is mpxml (my project xml) - the real file type is slightly more descriptive, but lets go with mpxml to keep it easy.

I think I know how to set a program to be a default application for a file type, but what I don't know, and can't find, is how that filename is passed to the application on launch.

IE, I double click a .mpxml file and it opens my application, and my application opens that file...

I'm picturing something like:

if (Application.Arguments.Filename != null)
{
Application.Run(new frmMain(Application.Arguments.Filename));
}

where frmMain would have an overloaded method to send the file path to a load project method once loaded.

Edit: This was marked as a duplicate, however, I had previously viewed the linked answer, and did not feel like it was a direct answer to my question- My answer below directly answers how to handle an application opening via a associated file.

Andy Stagg
  • 373
  • 5
  • 22

1 Answers1

0

Sorry, answered my own question after some additional googling using proper terminology.

I placed this in public frmMain(). problem solved. professionalism maintained.

foreach (string arg in Environment.GetCommandLineArgs())
{
    if (arg.Contains(".mspxml")) { loadProject(arg); }
}

It seems as if the first item in the array is always the name of the exe, which will differ if you're running a debug version vs a build. Either way, I was able to limit it to trying to open a file based on the .Contains. The loadProject method already contains error handling if a file is not a valid project file.

Andy Stagg
  • 373
  • 5
  • 22