How can I get a Silverlight application to check for an update and ask user to upgrade?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2010-06-13T15:29:50Z Indexed on 2010/06/13 16:32 UTC
Read the original article Hit count: 1282

Filed under:
|

I have made an out-of-browser silverlight application which I want to automatically update every time there is a new .xap file uploaded to the server.

When the user right-clicks the application and clicks on Updates, the default is set to "Check for updates, but let me choose whether to download and install them":

alt text

This leads me to believe that it is possible to make my Silverlight application automatically detect if there is a new .xap file present on the server, and if there is, the Silverlight client will automatically ask the user if he would like to install it.

  • This however is not the case. I upload a new .xap file and the Silverlight application does nothing.

  • Even if I add this to my App.xaml.cs:

--

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new BaseApp();
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.CheckAndDownloadUpdateAsync();
    }
}

and update the .xap file, the Silverlight application does nothing.

  • This information enabled me to check if there is an update and if so, tell the user to restart the application, but when he restarts the application, nothing happens:

--

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new BaseApp();
    if (Application.Current.IsRunningOutOfBrowser)
    {
        Application.Current.CheckAndDownloadUpdateAsync();
        Application.Current.CheckAndDownloadUpdateCompleted += new CheckAndDownloadUpdateCompletedEventHandler(Current_CheckAndDownloadUpdateCompleted);
    }
}

void Current_CheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
    if (e.UpdateAvailable)
    {
        MessageBox.Show("An application update has been downloaded. " +
            "Restart the application to run the new version.");
    }
    else if (e.Error != null &&
        e.Error is PlatformNotSupportedException)
    {
        MessageBox.Show("An application update is available, " +
            "but it requires a new version of Silverlight. " +
            "Visit the application home page to upgrade.");
    }
    else
    {
        //no new version available
    }
}

How do I make my Silverlight application check, each time it starts, if there is a new .xap file, and if there is, pass control to the Silverlight client to ask the user if he wants to download it, as the above dialogue implies is possible?

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about out-of-browser