0

I have a WPF app built with .Net 6.0 and deployed with ClickOnce as an offline-only application. I set a file association in my manifest file:

<fileAssociation
xmlns="urn:schemas-microsoft-com:clickonce.v1"
extension=".customext"
description="Custom File"
progid="0"
defaultIcon="AppIcon.ico"/>

When i deploy and install the application, the app is working fine and firing up when double-clicking a .customext file.

I need to read the file content, so I subscribed the Startup event in App.xaml:

Startup="Application_Startup"

Then, in App.xaml.cs:

private void Application_Startup(object sender, StartupEventArgs e)
{
    MainWindow mainWindow = new();
    foreach (string s in e.Args)
    {
        // Here I need to manage the file content
    }
    mainWindow.Show();
}

The problem is e.Args is always empty.

What I tried:

  1. Using Environment.GetCommandLineArguments()
  2. Overriding OnStartup event in App.xaml.cs

I previously got this working but it was a Net Framework application, so probably there's something different I'm not taking into account.

What am I doing wrong? I googled looking for solutions but most of the answers are Net Framework-realated and use the ActivationArguments class (solution not available in .Net Core).

IFrank
  • 419
  • 1
  • 5
  • 12

1 Answers1

0

Step-1:
   Update the VS2022 to the lastest version.
Step-2:
  Project RightClick => Publish => Publish-Tab => Show All => Setting-tab => Options => Allow Url-Paramaters....
Step-3:
  Copy this file code to you app.
Step-4:
  Write Fllowing code:

var clickOnceInfo = new ClickOnceInfo();
    if (!clickOnceInfo.IsNetworkDeployed)
    {
        MessageBox.Show(" app only can be start from Web Page,cant't direct start app");
        return;
    }
    var query = clickOnceInfo.ActivationUri?.Query ?? "QueryEMPTY";
    if (query == "QueryEMPTY")
    {
        MessageBox.Show("paramater empty,can't start app");
        return;
    }
sgf
  • 11
  • 2
  • Thank you for your answer, please can you translate strings to English? – IFrank Jan 09 '23 at 09:09
  • @PrivateFrank im update the strings.in my app,finaly im use the .application only to setup and update,im use URL Protocol to call the local app to startup. – sgf Jan 10 '23 at 14:26