System.IO.Packaging.PackagePart.GetStream() does not work if the package is hosted on a webserver (URL) RRS feed

  • Question

  • I have a package (System.IO.Packaging.Package) hosted on a webserver (URL) and, if I feed the package URL in web browser I can download the package.

    My requirement is to extract a single file (stream associated to a file) from the package without downloading the entire package.

    System.IO.Packaging has classes to allow manipulating packages. These classes work well if the package is located on a SMB share, but fails to extract file if the package is hosted on a web-server.

    It fails when I call PackagePart.GetStream() method, giving an exception which says that the stream is write-only and hence a read operation cannot be performed. I have tried using overloads of Package.Open() and PackagePart.GetStream() method passing read/write permissions but still it does not work.

    If I understand the stack trace correctly, somehow the stream instance in the MS.Internal.IO.Zip.ZipIOLocalFileBlock._blockManager does not have permissions propagated from the PackagePart.GetStream() call.

    Is this a bug? Did I do something wrong? Is there a workaround? I have been struggling for over two weeks now to get a solution for this problem and there is no ample documentation around usage of these classes.

    PS: I have already tried some popular Zip libraries (SharpZipLib, DontNetZip and .NET 4.5 ZipArchive class) they all fail to realize my requirement.

    Thank you.

    Friday, August 1, 2014 7:55 AM

All replies

  • Hi Hemaanshu,

    There is no present implementation. You need to write your own Stream to support your goal.


    Monday, August 4, 2014 5:24 AM