Starts the default app associated with the specified file, using the specified options.
Syntax
Windows.System.Launcher.launchFileAsync(file, options).done( /* Your success and error handlers */ );
Parameters
- file
-
Type: IStorageFile
The file.
- options
-
Type: LauncherOptions
The launch options for the app.
Return value
Type: IAsyncOperation<Boolean>
The launch operation.
Remarks
The calling app must be visible to the user when the API is invoked.
This API also imposes several restrictions on what types of files it can launch. Many file types that contain executable code, for example .exe, .msi, and .js files, are blocked from launching. This restriction protects users from potentially malicious files that could modify the system.
When the launch fails for any of the above reasons, the API succeeds and returns FALSE from its asynchronous operation. Since it has no ability to query whether the above restrictions apply to the current launch, the calling app should not assume that the launch succeeded, and should provide fallback mechanism in case it failed. A possible solution would be to ask the user to save the file and direct the user to open it in the desktop.
To enable the user to choose an app instead of launching the default app, set the LauncherOptions.DisplayApplicationPicker | displayApplicationPicker property.
To display a warning that the file is potentially unsafe, set the LauncherOptions.TreatAsUntrusted | treatAsUntrusted property.
The file is passed to the associated app. If the associated app is a desktop app, the file is passed using shell execution mechanisms.
Windows Phone 8
This API is not implemented and will throw an exception if called.
Examples
Call the Launcher.LaunchFileAsync(IStorageFile, LauncherOptions) | launchFileAsync(IStorageFile, LauncherOptions) method with LauncherOptions.DisplayApplicationPicker | displayApplicationPicker set to true to launch the app that the user selects for the file from the Open With dialog box.
// Path to the file in the app package to launch var imageFile = "images\\test.png"; // Get the image file from the package's image directory Windows.ApplicationModel.Package.current.installedLocation.getFileAsync(imageFile).then( function (file) { // Set the show picker option var options = new Windows.System.LauncherOptions(); options.displayApplicationPicker = true; // Launch the retrieved file using the selected app Windows.System.Launcher.launchFileAsync(file, options).then( function (success) { if (success) { // File launched } else { // File launch failed } }); });
Requirements
|
Minimum supported client | Windows 8 |
|---|---|
|
Minimum supported server | Windows Server 2012 |
|
Minimum supported phone | Windows Phone 8 |
|
Namespace |
|
|
Metadata |
|
See also
- Samples
- Association launching sample
- Guidelines
- Guidelines and checklist for file types and URIs
- Tasks
- How to launch the default app for a file (JavaScript)
- How to launch the default app for a file (C#/VB/C++)
- Reference
- Launcher
- LaunchFileAsync(IStorageFile, LauncherOptions)
Build date: 2/25/2013