我试图在Windows Phone 8.1中的C#中使用此库.http://epubreader.codeplex.com/根据初始化行中的文档,我们必须传递文件的路径.Epub epub = new Epub(@c:\example.epub);我使用文件选择器来选择文件,并通过了file....
![](https://oss.womengda.net/imgfile/2309/1E39A163R920-52239.jpg)
我试图在Windows Phone 8.1中的C#中使用此库.
http://epubreader.codeplex.com/
根据初始化行中的文档,我们必须传递文件的路径.
Epub epub = new Epub(@"c:\example.epub");
我使用文件选择器来选择文件,并通过了
file.path
作为参数.但在运行时会引发System.IO.FileNotFoundException.
如何将路径传递给库?
编辑
文件选择器代码 –
private void file_clicked(object sender, RoutedEventArgs e)
{
FileOpenPicker openPicker = new FileOpenPicker();
openPicker.ViewMode = PickerViewMode.Thumbnail;
openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
openPicker.FileTypeFilter.Add(".epub");
openPicker.PickSingleFileAndContinue();
}
编辑
将文件复制到应用程序本地文件夹
public async void ContinueFileOpenPicker(FileOpenPickerContinuationEventArgs args)
{
if (args.Files.Count > 0)
{
var file = args.Files[0];
Windows.Storage.StorageFolder localFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile;
await file.CopyAsync(localFolder, file.Name, NameCollisionOption.ReplaceExisting);
sampleFile = await localFolder.GetFileAsync(file.Name);
Epub epub = new Epub(sampleFile.Path); //exception occurs in this line
}
}
解决方法:
编辑
根据评论中的讨论和dBlisse的回答,问题是WP 8.1项目中不支持该库.
原始答案
我将离开原始答案,因为它解释了为什么该库在WP 8.1中不起作用.
精简版:
你正在混合System.IO(库)和Windows.Storage(选择器),这只能导致坏事.你从选择器返回的文件是通过Windows.Storage的代理文件.该库期望您具有进程内访问权限的文件,而不是代理文件.
The workaround is to copy the file to your apps local store using StorageFile.CopyAsync().将新文件的路径传递给库.
很长的故事
作为Windows Phone 8.1中沙盒过程的一部分,应用程序在本地应用程序容器外部没有读/写功能的进程中运行.防止应用程序对系统执行任何恶意操作.
要使应用程序能够访问应用程序容器外部的位置,可以使用名为runtimebroker.exe的系统进程.它需要访问系统的其他部分(通过KnownFolders,FilePicker等)并完成请求.它会检查以确保应用程序应该有权访问该位置,然后使用其权限打开句柄,并为应用程序提供一个StorageFile对象,该对象表示对文件的权限但不授予对应用程序的访问权限,仍然必须通过代理.
因此,应用程序永远不会拥有该位置的权限,但仍然可以使用runtimebroker作为代理访问那里的信息.这样做的副作用是当应用程序试图获取通过文件选择器检索的文件的句柄时(库正试图这样做),它会失败.
本文标题为:c# – 如何将文件从本地存储传递到Windows Phone 8.1中的库?
![](/xwassets/images/pre.png)
![](/xwassets/images/next.png)
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- .NET CORE DI 依赖注入 2023-09-27
- user32.dll 函数说明小结 2022-12-26
- 如何使用C# 捕获进程输出 2023-03-10
- Oracle中for循环的使用方法 2023-07-04
- Unity3D实现渐变颜色效果 2023-01-16
- c# 模拟线性回归的示例 2023-03-14
- Unity Shader实现模糊效果 2023-04-27
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16