首页 文章

Windows Phone epub阅读器

提问于
浏览
0

我'm trying to build a wp7 application that must allow user to read ebooks in epub format. Since there isn' t任何可用的库来读取Windows手机上的epub文件,我正在尝试创建一个 . 所以我必须解压缩文件,然后解析它 .
问题是我可以't unzip the epub file. I'使用 SharpZipLib.WindowsPhone7.dll 但我得到一个例外:

尝试访问该方法失败:System.IO.File.OpenRead(System.String)

在这条线上:

ZipInputStream s = new ZipInputStream(File.OpenRead(path_epubfile));

可以帮到我吗?

1 回答

  • 1

    这将取决于如何获得内容 . 这里有三种可能的选择;

    Option 1 :如果使用"Content"的Build Action将内容添加到项目中,则可以使用 StreamResourceInfo 类(在 System.Windows.Resources 名称空间中)获取流

    StreamResourceInfo info = Application.GetResourceStream(new Uri("MyContent.txt", UriKind.Relative));
      using (info.Stream) {
        // Make use of the stream as you will
      }
    

    Option 2 :如果你've added it to your project and set the Build Action to 1048284 then you' ll需要使用 GetManifestResourceStream()

    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("ProjectName.MyContent.txt")) {
      // Make use of stream as you will
    }
    

    注意:您需要将"EPubReader.Example.txt"传递给 GetManifestResourceStream() . 您可以使用 GetManifestResourceNames() 查看可用的资源 .

    Option 3 :如果您've obtained the content at run time, it'将存储在 IsolatedStorage 中 .

    using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) {
      using (IsolatedStorageFileStream stream = store.OpenFile("MyContent.txt", FileMode.Open)) {
        // Make use of stream as you will
      }
    }
    

相关问题