Reputation: 15200
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".
Upvotes: 3
Views: 5657
Reputation: 159
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
!
Upvotes: 8
Reputation: 1043
I think all you can do is save the URI somewhere when the application downloads and runs the first time and then reference this value when the application runs offline.
Upvotes: 1
Reputation: 11227
Try ApplicationDeployment.UpdateLocation property. Unless you have configured a different update URL in the Project Properties -> Publish -> Updates -> Update Location in Visual Studio, it should return you the original deployment URL.
Upvotes: 2