We have some code that has been running for years that creates PDFs from a SSRS Report. We've created literally millions of documents thru this code.
Recently on our development server, we started getting sporadic "System.IO.IOException: The process cannot access the file 'xx786801.pdf' because it is being used by another process" messages on PdfSharp.Pdf.PdfDocument.Save Yes! We are using a unique file name, and this process has been working for years. No code changes; no hardware changes; and this is sporadic. Tried a reboot. The process will create 50-75 documents and then get this exception. we can continue with another 50-70 and another exception.
The code creating the document looks like this:
Code:
Dim stream As System.IO.FileStream = System.IO.File.Create(OutDir + FileName, result.Length)
stream.Write(result, 0, result.Length)
stream.Close()
stream.Dispose()
And then we run a function that locks the PDF that looks like this:
Code:
Dim document As PdfSharp.Pdf.PdfDocument = PdfReader.Open(Filename, MyPW)
Dim SecuritySettings As PdfSharp.Pdf.Security.PdfSecuritySettings = document.SecuritySettings
If PasswordRequiredOnOpen = True Then
SecuritySettings.UserPassword = MyPW
End If
' setting the owner password will restrict things like editing and printing
SecuritySettings.OwnerPassword = MyPW
SecuritySettings.PermitAccessibilityExtractContent = False
SecuritySettings.PermitAnnotations = False
SecuritySettings.PermitAssembleDocument = False
SecuritySettings.PermitExtractContent = False
SecuritySettings.PermitFormsFill = False
SecuritySettings.PermitFullQualityPrint = True
SecuritySettings.PermitModifyDocument = False
SecuritySettings.PermitPrint = True
document.Save(Filename)
document.Close()
document.Dispose()
Just not too sure where to even start on this. Any ideas?
Dan