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
Asked
Active
Viewed 1,599 times
0
-
Share with us more about the exception, yor're receiving. – KamikyIT Jul 11 '17 at 15:12
1 Answers
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
-
yes, I'm getting "A disk error occurred during a write operation.". Also I do not know the password. – Z . Jul 11 '17 at 16:48
-
strange... can you share the exact line of code in which you are getting this exception ? – Subbu Jul 11 '17 at 17:15
-