我有一个Windows 10 UWP应用程序,它将向用户显示办公文档列表。当用户单击其中一个文档时,我想在设备上启动现有的办公应用程序以查看和编辑该文档。实现它的最佳方法是什么。我是Windows 10的新手。
谢谢!
答案 0 :(得分:4)
我们可以使用Launcher.LaunchFileAsync
方法启动现有办公应用,以查看和编辑办公文档。例如,使用LaunchFileAsync(IStorageFile)
方法启动与指定文件关联的应用程序:
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);
}
}
除此之外,我们还可以使用LaunchFileAsync(IStorageFile, LauncherOptions)
方法。此方法使用指定的选项启动与指定文件关联的默认应用程序。例如,我们可以将LauncherOptions.DisplayApplicationPicker
设置为true
来调用此方法,以启动用户从“打开方式”对话框中选择的应用。有关详细信息,请参阅Launch the default app for a file。