我有一些pdf文件里面(项目文件)我的应用程序,我想如何在Adobe Reader或其他打开,但我不知道如何。如何在Windows Phone 8中打开pdf文件?
在iOS中更简单,在Android中我知道如何,但我不知道WP8如何。
我是Windows Phone 8的新手:/
谢谢大家!
我有一些pdf文件里面(项目文件)我的应用程序,我想如何在Adobe Reader或其他打开,但我不知道如何。如何在Windows Phone 8中打开pdf文件?
在iOS中更简单,在Android中我知道如何,但我不知道WP8如何。
我是Windows Phone 8的新手:/
谢谢大家!
您必须使用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
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文件生成操作内容
保存下载文件到独立的存储.. 。
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);
有了这个代码应用程序显示这样的错误:线程0xf68已退出与代码259(0x103)。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):加载'C:\ windows \ system32 \ System.Runtime.ni.dll'。跳过的加载符号。模块已经过优化,调试器选项“Just My Code”已启用。 'TaskHost.exe'(CLR C:\ windows \ system32 \ coreclr.dll:Silverlight AppDomain):Loaded'C:\ windows \ system32 \ en-US \ mscorlib.debug.resources.dll'。模块没有符号。 mscorlib.ni.dll中发生类型'System.IO.FileNotFoundException'的第一次机会异常 –
file.pdf与App.xml –
处于同一级别,但是,我的文件的路径是什么? –