File is locked by process

Hi,

Please refer to the attachment for the sample code. Basically i am trying to execute the application using Task Parallel Library.

Unfortunately at the following line, the application throws the exception that the file is being used / locked by a process

pdfDocWithOMR.Save(fileWithOMR);

I have tried to limit by executing only a single task, and it still throws the same exception. It's a bit weird because there is no such file exist in the actual destination folder, but the application still throws the exception.

Regards,

hadi teo

Hi Hadi,


Thanks for contacting support.

I have tried executing the solution but I am afraid I am getting “Invalid Resx file. Could not find file ‘C:\pdftest\WindowsFormsApplication1\Properties\Resources.resx’.”. Can you please again include this missing file and share the solution so that we can again test the scenario. We are sorry for this inconvenience.

PS, I have tried adding one of my sample .resx file but its not working.

Hi,

I have attached the updated attachment with the missing file.

Regards,

hadi teo

Hi Hadi,


Thanks for sharing the sample projects.

I
have tested the scenario and I am able to reproduce the same problem. For the
sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-34826. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We
apologize for your inconvenience.

Hi Nayyer,

Thanks for your assistance. Please inform me further if there are any updates.

Regards,

hadi teo

Hi Hadi,


Thanks for your patience. We have further investigated the sisue PDFNEWNET-34826 and as per our observations, you need to update your code in order to get this issue resolved. In ProductPdfIndirect method, after stamping, code for saving the document is written in the following way:

[C#]

string fileWithoutOMR = Path.Combine(folderPath,
“Test.pdf”);<o:p></o:p>

string fileWithOMR = Path.Combine(folderPath, "Test OMR " + docNumber.ToString() + ".pdf");

Aspose.Pdf.Document pdfDocWithOMR = DrawOMROnPDFUsingPdfFileStamp(pdfDocWithoutOMR);

using (FileStream fileStream = new FileStream(fileWithOMR, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))

{

pdfDocWithOMR.Save(fileWithOMR);

Where FileStream is created for writing, and at the same time you are trying to save document with specified file name (as a result, another file stream is created for the same file). In order to fix this problem, you could pass fileStream into Save() method instead of file name.

using (FileStream fileStream = new FileStream(fileWithOMR, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))

{

//pdfDocWithOMR.Save(fileWithOMR); <--- this is incorrect

pdfDocWithOMR.Save(fileStream);


PS, You have created FileStream for resultant file, that's why he should save document into the stream instead of specifying file name in save method (this causes to create new file stream for writing into the same file and as result a conflict between two file stream objects). Changes are required in ProductPdfIndirect method.

The issues you have found earlier (filed as PDFNEWNET-34826) have been fixed in Aspose.Pdf for .NET 7.7.0.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.