We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

EncryptFile leaves output file in use

Following your sample code, this will leave the outFile in use by the worker process:

Dim inFile As String = "infile.PDF" 'This is a sample PDF. Any PDF is fine.

Dim outFile As String = "outfile.PDF" 'This is a new file, it does not exist yet

Dim fileSecurity As Aspose.Pdf.Kit.PdfFileSecurity = New Aspose.Pdf.Kit.PdfFileSecurity(inFile, outFile)

fileSecurity.EncryptFile("password", "password", Aspose.Pdf.Kit.DocumentPrivilege.Print, Aspose.Pdf.Kit.KeySize.x128)

Once that code runs, it encrypts outfile.PDF. Now try to delete outfile.PDF from the directory. You can't. It's still open and in use. The only way to delete it would be to run IISRESET.

How can the file be released properly?

Using version and IIS7.

thank you.


Hi David,

I have tested this issue at my end using different sample files and running the application on IIS 7, however I couldn’t notice any such problem. In order to understand and then resolve this issue, it is very important for our team to reproduce the issue at our end. We would really appreciate your cooperation in this regard. Please share a small sample application – which can reproduce the same issue at our end – along with the sample input PDF file. We’ll test the issue with that and update you accordingly.

We’re sorry for the inconvenience.

Hi and thanks for your reply.

That's my code, that's it. Just run it and then try to delete the newly created encrypted output PDF file in the directory. Windows says the file is in use. It doesn't matter which PDF you use, you can use anything.


Hi David,

I used the same code you shared, but I couldn’t reproduce this issue; I could delete the files manually and using File.Delete method as well. I would like to share with you that some times the issue might be caused due to the particular contents or origin of the PDF files; for example, the particular files created with some particular tool, in some specific way, with certain contents might be forcing the component to leave it open. Therefore, it is very important for us to reproduce the issue using your particular scenario.

I would really appreciate if you could share a small sample application along with a sample PDF file with us; if you want to keep the files confidential, you can mark this post as private or send the file using ‘Contact -> Send shahzad.latif an email’ option at the top of this post. Moreover, you might also try our latest version at your end.

We’re sorry for the inconvenience and looking forward to help you out.