SurenderS
SurenderS

Reputation: 29

Open office documents on windows 10 UWP (Phone)

I have a windows 10 UWP app that will display a list of office documents to the user. When user clicks one of these documents, I want to launch the existing office apps on the device to view and edit that document. What is the best way to achieve it. I'm new to windows 10.

Thanks!

Upvotes: 1

Views: 1055

Answers (1)

Jay Zuo
Jay Zuo

Reputation: 15758

We can use Launcher.LaunchFileAsync method to launch the existing office apps to view and edit office documents. For example, using LaunchFileAsync(IStorageFile) method starts the app associated with the specified file:

private async void Button_Click(object sender, RoutedEventArgs e)
{
    //Retrieve document for LocalFolder
    var file = await ApplicationData.Current.LocalFolder.GetFileAsync("Test.docx");

    if (file != null)
    {
        // Launch the retrieved file
        await Windows.System.Launcher.LaunchFileAsync(file);
    }
}

Besides this, we can also use LaunchFileAsync(IStorageFile, LauncherOptions) method. This method starts the default app associated with the specified file, using the specified options. Such as we can call this method with LauncherOptions.DisplayApplicationPicker set to true to launch the app that the user selects from the "Open With" dialog box. For more information, see Launch the default app for a file.

Upvotes: 4

Related Questions