1. Go to the Properties of the Windows/WPF project. In the Publish tab set the publish location. Here I have published my application to an IIS Web site.
2. Right click on the Windows/WPF project and select Publish. Follow the publish wizard. After successful Publish, if you go to the physical path of the Web site, published content can be seen as follows.
Then we can register a JavaScript in our ASP.NET Web application to download the desktop application as follows.Method 1 : window.open
///
/// Register client script to launch desktop application.
/// Method 1 : window.open
///
private void LaunchApplicationMethod1()
{
string clientApplicationURL = "http://localhost:82/MyCliclOnceApp.application";
System.Text.StringBuilder jScript = new System.Text.StringBuilder();
jScript.Append("");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LaunchClientApplicationBlock", jScript.ToString());
}
Method 2 : window.location.href
///
/// Register client script to launch desktop application.
/// Method 2 : window.location.href
///
private void LaunchApplicationMethod2()
{
string clientApplicationURL = "http://localhost:82/MyCliclOnceApp.application";
System.Text.StringBuilder jScript = new System.Text.StringBuilder();
jScript.Append("");
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "LaunchClientApplicationBlock", jScript.ToString());
}
As you can notice I have passed two arguments to the desktop application through launching client script. They can be consumed in the desktop application as follows.
private void Application_Startup(object sender, StartupEventArgs e)
{
try
{
int? clientId = null;
int? clientType = null;
if (ApplicationDeployment.IsNetworkDeployed)
{
// Loaded from the web?
if (ApplicationDeployment.CurrentDeployment.ActivationUri != null)
{
string queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
string value1 = HttpUtility.ParseQueryString(queryString)["ClientId"];
queryString = ApplicationDeployment.CurrentDeployment.ActivationUri.Query;
string value2 = HttpUtility.ParseQueryString(queryString)["ClientType"];
try
{
clientId = int.Parse(value1);
clientType = int.Parse(value2);
}
catch
{ }
}
}
}
catch (Exception ex)
{ }
}