PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Setting a file free after rendering it?
https://forum.pdfsharp.net/viewtopic.php?f=2&t=4245
Page 1 of 1

Author:  Notion [ Fri Apr 09, 2021 2:25 pm ]
Post subject:  Setting a file free after rendering it?

Hey everyone, when I call a method which executes the following code (Rendering a pdf) the second time on the same output file location with the same output file name, I get an exception. I feel like I miss something like Renderer.Document.Close() to avoid the blocking but I can not find such a function. Any help?

Code:
           //save pdf document
            PdfDocumentRenderer renderer = new PdfDocumentRenderer();
            renderer.Document = doc;
            renderer.RenderDocument();
            renderer.Save(pdfsavefullpath);

Author:  TH-Soft [ Fri Apr 09, 2021 2:59 pm ]
Post subject:  Re: Setting a file free after rendering it?

If the file is opened by e.g. Adobe Reader then it is locked and cannot be overwritten.

Posting exception details may help, the picture on my crystal ball is a bit unclear.

Author:  Notion [ Fri Apr 09, 2021 3:06 pm ]
Post subject:  Re: Setting a file free after rendering it?

Yea, I assumed that opening via any reader will lock it. The only thing I do though is (in the same program) handing it over as an attachment to an smtp client, which should just send it and after sending (probably? hopefully?) not locking the whole file until the end of the program (the mail message is out of scope quite quickly, since it is only constructed and refered to in a function thats called every now and then and quickly sends out a mail and then returns). I will investigate if smtp blocks it, but I am still doubting it.

Error is this:
System.IO.IOException: 'The process cannot access the file 'C:\Users\patri\source\repos\automailer\automailer\bin\Debug\netcoreapp3.1\Output\Zertifikat.pdf' because it is being used by another process.'

Author:  TH-Soft [ Mon Apr 12, 2021 8:06 am ]
Post subject:  Re: Setting a file free after rendering it?

Notion wrote:
Error is this:
System.IO.IOException: 'The process cannot access the file 'C:\Users\patri\source\repos\automailer\automailer\bin\Debug\netcoreapp3.1\Output\Zertifikat.pdf' because it is being used by another process.'
With the process viewer from SysInternals you can find out which process locks the file - in case it is locked long enough to take a look.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/