0

What is the correct way to check is an excel file is password protected (I do not know the password)? When I try to open it I get a non-specific exception ("A disk error occurred during a write operation.") that could be related to any other type of invalid file. Thanks

Z .
  • 12,657
  • 1
  • 31
  • 56

1 Answers1

0

If I try to open a password protected xlsx file, I get the exception -

{"Can not open the package. Package is an OLE compound document. If this is an encrypted package, please supply the password"}

It also suggests using the overloaded method to open it

sample:

string mySpreadsheetName = @"path/to/file/name/xlsx";
FileInfo fi = new FileInfo(mySpreadsheetName);
ExcelPackage p1 = new ExcelPackage(fi, "abcd"); // this opens correctly, here "abcd" is the password
ExcelPackage p2 = new ExcelPackage(fi); //this throws an exception

Are you getting a different exception ?

Subbu
  • 2,130
  • 1
  • 19
  • 28