Skip to content

Detecting password protected files #1650

@kemsky

Description

@kemsky

NPOI Version Used

2.7.5

File Type

  • XLSX
  • XLS
  • DOCX
  • XLSM
  • OTHER

Use Case

Sometimes files are password protected and we get an exception trying to open it:

ICSharpCode.SharpZipLib.Zip.ZipException: EOF in header
   at ICSharpCode.SharpZipLib.Zip.Compression.Streams.InflaterInputBuffer.ReadLeByte()
   at ICSharpCode.SharpZipLib.Zip.ZipInputStream.SkipUntilNextEntry()
   at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry()
   at NPOI.OpenXml4Net.Util.ZipInputStreamZipEntrySource..ctor(ZipInputStream inp)
   at NPOI.OpenXml4Net.OPC.ZipPackage..ctor(Stream in1, PackageAccess access)
   at NPOI.OpenXml4Net.OPC.OPCPackage.Open(Stream stream, Boolean readOnly)
   at NPOI.Util.PackageHelper.Open(Stream stream, Boolean readOnly)
   at NPOI.XWPF.UserModel.XWPFDocument..ctor(Stream is1)

Description

It would be nice to have at least a meaningful exception thrown or a way to check that file is protected.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions