1

I have C# WinForm .NET 4.5 application. I set Project -> Properties -> Publish -> Options -> File Associations. This part seems to work because it sets icon that I selected and if I double click file with custom extension (in this case *.psi) it opens my application. But I am having hard time getting file name that was double clicked. Somehow my static void Main(string[] args) args are always empty. I use ClickOnce deployment method.

Can anyone help me with what I am missing to open custom file with my application.

static void Main(string[] args)
    {
        if(args.Length > 0)
        {
            MessageBox.Show(args[0]);
        }else {
          MessageBox.Show("args is empty!");
        }

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        DevExpress.Skins.SkinManager.EnableFormSkins();

        UserLookAndFeel.Default.SetSkinStyle(Properties.Settings.Default.ActiveSkinName);


        Application.Run(new MainForm(args));
    }
Farukh
  • 2,173
  • 2
  • 23
  • 38

1 Answers1

2

Found the solution here.

When you publish an app with ClickOnce and then launch it by double-clicking an associated file, the path to that file actually gets stored here:

AppDomain.CurrentDomain.SetupInformation.ActivationArguments.ActivationData[0]

See MSDN's documentation for it here:

http://msdn.microsoft.com/en-us/library/system.runtime.hosting.activationarguments.aspx

Plus a tutorial on adding file associations to "Published" projects:

http://blogs.msdn.com/b/mwade/archive/2008/01/30/how-to-add-file-associations-to-a-clickonce-application.aspx

Community
  • 1
  • 1
Farukh
  • 2,173
  • 2
  • 23
  • 38
  • Copy-pasting whole answer is generally not recommended - you could flag your question to be closed as duplicate (which is perfectly fine way to mark question as solved problem). – Alexei Levenkov Feb 26 '15 at 01:50