我的应用程序里面有一些pdf文件(项目文件)我想要如何在Adobe Reader或其他文件中打开,但我不知道如何。
在iOS中更容易,在Android中我知道如何,但我不知道在WP8中如何。
我是Windows Phone 8的新手:/
谢谢大家!
答案 0 :(得分:6)
您必须使用Launcher
类的LaunchFileAsync
方法。例如:
// Access the file.
StorageFile pdfFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync("file.pdf");
// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdfFile);
您可以在此处找到更多信息:
Auto-launching apps using file and URI associations for Windows Phone 8
答案 1 :(得分:2)
将下载的文件保存到隔离存储...
async void client_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
byte[] buffer = new byte[e.Result.Length];
await e.Result.ReadAsync(buffer, 0, buffer.Length);
using (IsolatedStorageFile storageFile = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream stream = storageFile.OpenFile("your-file.pdf", FileMode.Create))
{
await stream.WriteAsync(buffer, 0, buffer.Length);
}
}
}
打开并显示隔离存储中的pdf文件..
// Access the file.
StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile pdffile = await local.GetFileAsync("your-file.pdf");
// Launch the pdf file.
Windows.System.Launcher.LaunchFileAsync(pdffile);
答案 2 :(得分:0)
async void launchPDF()
{
string fileURL = @"Assets\file.pdf";
StorageFile pdfFile = await
Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(fileURL);
if (pdfFile != null)
{
IAsyncOperation<bool> success =
Windows.System.Launcher.LaunchFileAsync(pdfFile);
if (await success)
{
// File launched
}
else
{
// File launch failed
}
}
else
{
}
}
确保pdf文件构建操作是内容