This is not working for me:
- Code: Select all
PdfDocument doc = new PdfDocument();
12
doc.LoadFromFile(@"C:\Users\Administrator\Desktop\Encrypted.pdf");
13
14
bool isEncrypted = doc.IsEncrypted;
hoping someone can help. I need KEEP the password protected files in a directory and DELETE those pdfs that are NOT password protected.
I get the exception thrown saying it is password protected and so the boolean .IsEncrypted never gets set due to the exception. How can I test if encrypted without an exception being thrown?
Here is what I am trying to do:
- Code: Select all
foreach (FileInfo file in di2.GetFiles())
{
try
{
Spire.Pdf.PdfDocument doc = new Spire.Pdf.PdfDocument();
doc.LoadFromFile(environnementSubFolder + "\\" + file));
bool isEncrypted = doc.IsEncrypted;
if (isEncrypted)
// Do nothing
else
file.Delete();
}
catch (Exception e)
{
throw new Exception("Encrypted: " + e.Message);
}
}
Thanks,
Ryan