One of the exciting new features of Silverlight 3 is the ability to take an application offline. In order to take advantage of this feature you must do three things:

  1. Establish Application’s Offline Identity.
  2. Detach the application.
  3. Handle when running offline.

Step 1: Establish Application’s Offline Identity

The application’s offline identity is defined in a file called AppManifest.xml that lives in the Properties folder of any standard Silverlight Application project. Within this file you can do a number of things, such as specify icons and other dependent packages or assemblies.

<Deployment.Parts>
</Deployment.Parts>
<Deployment.ApplicationIdentity>
    <ApplicationIdentity 
        ShortName="Hello World!" 
        Title="Offline Hello World!">
        <ApplicationIdentity.Blurb>
          This application greets the world with gleeful exuberance.
        </ApplicationIdentity.Blurb>
    </ApplicationIdentity>
</Deployment.ApplicationIdentity>

Step 2: Detach the application

The Application object exposes a new method called Detach to initiate the process of sending an application offline.

App.Current.Detach();

It’s important to make sure that you determine whether the application has already been detached because if it has then calling this method will only result in an Invalid Operation Exception. However, if it happens to be the first time the user has taken this application offline they will immediately be greeted by the prompt below asking them if they truly want to install the application onto their computer.

After an application has been taken offline. You can right click anywhere inside of it and select “Remove this application”.

Step 3: Handle when running offline

The Application object exposes two new properties that allow you to check whether the application has ever been detached and whether the current instance of the application is an offline version.

Execution State defaults to RunningOnline. After an application has been detached, however, it changes to Detached.

App.Current.ExecutionState

The running Offline flag is false when the user opens the application through the browser; likewise, it is true when the user opens the application from the Desktop or Start Menu short cuts that were created.

App.Current.RunningOffline