I have a program that has a file type associated with it (*.cqd). When the user double clicks a .cqd file, it opens up my program just fine, but I can't for the life of me get the name/path of the file used to open the program.
I've tried the following code:
public static void Main(string[] args)
{
foreach (string s in args)
{
MessageBox.Show("MAIN: " + s);
}
}
Which only gives me the path of the program itself.
I've also tried:
foreach (string arg in Environment.GetCommandLineArgs())
{
MessageBox.Show(arg);
}
Which has the same effect. I'm having a hard time finding information on the topic because my searches give me "How do I open a file with it's associated program?" rather than the problem I'm having. Any help I can get would be appreciated.
NINJA EDIT: This is not a WPF project. Sorry I wasn't specific on that. I also fixed a quick typo.
FOUND THE PROBLEM! When I publish the application, it publishes to a .application file. I went into the project's /bin/release/ folder and found the .exe file. When I drag a file onto the .exe, it properly passes the path into the arguments. Guess I need to read up more on why this is, and if I can get the .application file to work with arguments, seeing as how it has the auto-update of ClickOnce in it.
Thank you all for your help! If there's anything I need to do to close this thread, please let me know.
AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]
Works as well for ClickOnce activations
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