Hello,
i have a problem with the Report.Publish() method. It throws exception like this:
Exception: The process cannot access the file 'XXX.pdf' because it is being used by another process.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode)
at Infragistics.Documents.Reports.Report.Report.Publish(String fileName, FileFormat format)
Does anyone know what's the problem is?
Thanks for your answers.
Greets,
Teddy
Hi Teddy,
That error message is pretty clear-cut. It means that some other application has the file locked and it therefore cannot be overwritten. This would happen, for example, if you have that PDF file currently open in Adobe Acrobat (or some other PDF reader).
Hi Mike,
There are two situations:
1. There is already a pdf file at the directory, the publish method will modify the existed file.
2. There is no such file at the giving directory, the publish method will create a file and write data.
Is there any chance to throw this exception under situation 2?
Please forgive my poor English.
Thanks
In my case, the file is created by the Publish() method, so I don't know what caused the file being processed inside the method.
If the file did not exist, then I don't see any way this exception could possibly occur. The exception means that the file you are trying to save to already exists and that the file is in use by some other application. That's the only case I've ever seen this exception.
Maybe your code is trying to Publish the same file twice or something like that. So it's failing the second time because your application still has the file open.
If you can post a small sample project demonstrating this occurring when the file does not exist, I'd love to take a look at it and see what's going on. But like I said, I've never seen that happen before and I cannot imagine how it possibly could.
BTW... it's easy enough to check this by using File.Exists in your code to see if the file is already there or not. I don't know if there's any way to detect if it's currently in use, though.
Thanks, I have checked the file generate folder, the file exists.
So that seems to indicate that there's some basic assumption you are making there that is incorrect. Becuase earlier you said the file did not already exist.
The next question then becomes - what application is locking the file. If you are not running Acrobat or some other PDF reading and don't have that file open at the time you are getting the error, then that means your application probably still has that file locked for some reason and you are trying to write it twice or something like that.