ClickOnce application when run from start menu gets the URL it was originally downloaded from

clickonce

Our users run our ClickOnce WPF application from the start menu / desktop shortcut. When the application starts each time we need to get the URL it was originally downloaded from. I tried using the ActivationUri, but this only works when it was run directly from the website setup.exe rather than the desktop / start menu shortcut:

string activationUri = "???";
try
{
    if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment == null)
    {
        activationUri = "currentDeployment is null";
    }
    else if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri == null)
    {
        activationUri = "deployment not null but uri is";
    }
    else if (System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri != null)
    {
        activationUri =
            System.Deployment.Application.ApplicationDeployment.CurrentDeployment.ActivationUri.AbsoluteUri;
    }
}
catch (Exception ex)
{
    activationUri = ex.Message;
    //Error getting the URL so put question mark
}

MessageBox.Show(activationUri);

When run from the setup (from a website) I would get the URL, and every other time I would get "deployment not null but URI is".

Best Answer

ApplicationDeployment.CurrentDeployment.ActivationUri

is not null if you activate the "Allow URL Parameters to be passed to the application" checkbox in the Publish Manifest options.

Otherwise use ApplicationDeployment.CurrentDeployment.UpdateLocation!