[]
Determines whether the specified file stream is password protected.
Use this method before opening a workbook stream to decide whether a password should be supplied to Open(Stream, string, OpenOptions).
public bool IsEncryptedFile(Stream fileStream)
Public Function IsEncryptedFile(fileStream As Stream) As Boolean
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The input file stream to inspect. |
| Type | Description |
|---|---|
| bool | true if the specified file stream is password protected; otherwise, false. |
worksheet.Range["A1"].Value = "Confidential";
using (MemoryStream fileStream = new MemoryStream())
{
string password = GetPasswordFromSecureSource();
XlsxSaveOptions options = new XlsxSaveOptions();
options.Password = password;
workbook.Save(fileStream, options);
fileStream.Position = 0;
bool encrypted = workbook.IsEncryptedFile(fileStream);
}
Determines whether the specified file is password protected.
Use this method to check whether a workbook file requires a password before opening it. If the file is encrypted, open it with Open(string, string, OpenOptions).
public bool IsEncryptedFile(string fileName)
Public Function IsEncryptedFile(fileName As String) As Boolean
| Type | Name | Description |
|---|---|---|
| string | fileName | The name or path of the file to check. Must not be null. |
| Type | Description |
|---|---|
| bool | true if the specified file is password protected; otherwise, false. |
string password = GetPasswordFromSecureSource();
string fileName = Path.Combine(Path.GetTempPath(), Path.ChangeExtension(Path.GetRandomFileName(), ".xlsx"));
XlsxSaveOptions options = new XlsxSaveOptions();
options.Password = password;
workbook.Save(fileName, options);
bool isEncrypted = workbook.IsEncryptedFile(fileName);
| Type | Condition |
|---|---|
| IOException | Thrown when the specified file cannot be opened for reading. |
| UnauthorizedAccessException | Thrown when the caller does not have permission to access the specified file. |