Launching a File

Any app can request that the OS launch a file. Launching a file is achieved using the Windows.System.Launcher class. The following excerpt from the MainPageViewModel retrieves a file stored in the app’s private storage area and launches it using the Launcher’s LaunchFileAsync method:

async Task LaunchFile(){    StorageFolder folder = ApplicationData.Current.LocalFolder;    StorageFile file = await folder.GetFileAsync("Sample.unl");    Launcher.LaunchFileAsync(file);}

The path to the file must exist. If the file does not exist, a FileNotFoundException is raised.

The MainPageViewModel in the WPUnleashed.AppThatLaunchesACustomFileType project saves a sample file with the .unl extension (see Listing ...

Get Windows® Phone 8 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.