Two simple methods for ClickOnce deployed applications.
public static class ClickOnce
{
/// <summary>
/// Determines whether this instance is deployed.
/// </summary>
/// <returns>
/// <c>true</c> if this instance is deployed; otherwise, <c>false</c>.
/// </returns>
public static bool IsDeployed()
{
return (AppDomain.CurrentDomain.ActivationContext != null && ApplicationDeployment.IsNetworkDeployed);
}
/// <summary>
/// Parses the query string.
/// </summary>
/// <returns><see cref="NameValueCollection"/> containing the key/value pairs from the ActivationUri if they are found; otheriwise an empty <see cref="NameValueCollection"/>.</returns>
public static NameValueCollection ParseQueryString()
{
if (!IsDeployed())
return new NameValueCollection();
Uri uri = ApplicationDeployment.CurrentDeployment.ActivationUri;
if (uri != null)
{
NameValueCollection parms = HttpUtility.ParseQueryString(uri.Query);
if (parms.Count != 0)
return parms;
}
return new NameValueCollection();
}
}