Welcome Guest Search | Active Topics | Sign In | Register

The process cannot access the file 'File.pdf' because it is being used by another process Options
Michael
Posted: Tuesday, April 2, 2013 5:30:32 PM
Rank: Newbie
Groups: Member

Joined: 3/25/2013
Posts: 8
I have a very odd problem when trying to convert an asp page to PDF using this code:
Code: C#
protected void ASPXToPDF1_AfterRender(object sender, EventArgs e)
    {
        EO.Pdf.HtmlToPdfResult result = (EO.Pdf.HtmlToPdfResult)ASPXToPDF1.Result;
        string fileName = HttpContext.Current.Server.MapPath(@"~\File" + ID + ".pdf");
        result.PdfDocument.Save(fileName); //<---- Exception generated here
}

I receive the error below. Here are some details:
1. It works fine on our public web server but not our development machines.
2. The file does not exists before calling Save method.
3. The file is found created after the exception is generated but it is zero bytes long
4. Using Windows 8 and Visual Studio 2012

Any help would be greatly appreciated.
Michael


System.IO.IOException was unhandled by user code
HResult=-2147024864
Message=The process cannot access the file 'C:\Dev\Projects\Ticket Commerce\2.7.0.0\NSiteTicketCommerce\NSiteTicketCommerce\File70512452-ad33-48a2-ae30-8d0775022cd5.pdf' because it is being used by another process.
Source=mscorlib
StackTrace:
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 EO.Pdf.Internal.hj.b(String A_0)
at EO.Pdf.PdfDocument.Save(String fileName)
at ASP.waiverform70512452_ad33_48a2_ae30_8d0775022cd5_aspx.ASPXToPDF1_AfterRender(Object sender, EventArgs e) in c:\Dev\Projects\Ticket Commerce\2.7.0.0\NSiteTicketCommerce\NSiteTicketCommerce\WaiverForm70512452-ad33-48a2-ae30-8d0775022cd5.aspx:line 79
at EO.Web.ASPXToPDF.a(String A_0, Stream A_1)
at EO.Web.Internal.ms.a(b[] A_0)
at EO.Web.Internal.ms.a.Close()
at System.Web.HttpWriter.FilterIntegrated(Boolean finalFiltering, IIS7WorkerRequest wr)
at System.Web.HttpResponse.FilterOutput()
at System.Web.HttpApplication.CallFilterExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
InnerException:
eo_support
Posted: Tuesday, April 2, 2013 6:50:52 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

This is something that you have to troubleshoot. Basically you are trying to save the PDF file into a file and that file is currently open somewhere else. A typical example of this is when you run it once, creating the file without any problem, then open the file with Adobe Reader, then run it again, in that case you will hit this problem. However this is just an example, the actual situation can be different. But none has anything to do the converter ---- it's just the file is being locked by something else.

Thanks!
Michael
Posted: Wednesday, April 3, 2013 11:57:55 AM
Rank: Newbie
Groups: Member

Joined: 3/25/2013
Posts: 8
The odd thing about this issue is that the pdf file does not exist before calling the save method . Therefore it could not be open. No other code can be called when while within the save method, there is only one session. Also it seems that the file is partially created (0 bytes) after the save method is called and exception is given. I don't think that this is a problem with the component. Any other suggestions of what could be causing this?

EDIT: I try and delete the zero byte file while IIS Express is running I get: the action con't be completed because the file is open in IIS Express Worker Process.

Thanks

Michael
eo_support
Posted: Wednesday, April 3, 2013 12:02:11 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,195
Hi,

You may want to just write some generic code to create and write some contents into that file and then start from there. That way you can by pass our component and if the problem still occurs, then obviously the problem is somewhere else.

Thanks
Michael
Posted: Wednesday, April 3, 2013 5:44:03 PM
Rank: Newbie
Groups: Member

Joined: 3/25/2013
Posts: 8
I found the problem. Some code was causing the save method to be executed more than once in another thread.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.