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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.