How to check if file is encrypted

The encryption is used to protect the file, so the only people with an encryption key (such as a password) can open and view a file. In case you want to check if a file is encrypted, you can use GetFileInfo() method that returns file type and flag that indicates if the file is encrypted as it is shown in the next example (this example can be found in our examples at GitHub.)

using (Viewer viewer = new Viewer("encrypted.pdf"))
{
    FileInfo fileInfo = viewer.GetFileInfo();

    Console.WriteLine("File type is: " + fileInfo.FileType);
    Console.WriteLine("File encrypted: " + fileInfo.Encrypted);
}

After running the code above you will see an output like this:

File type is: Portable Document Format File (.pdf)
File encrypted: True

To learn how to open an encrypted file please refer to Load password-protected document documentation article.

More resources

Advanced Usage Topics

To learn more about document viewing features, please refer to the advanced usage section.

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.