PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Sat Jun 19, 2021 7:25 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Fri Apr 09, 2021 2:25 pm 
Offline

Joined: Thu Apr 08, 2021 12:39 pm
Posts: 3
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);


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 09, 2021 2:59 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 644
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
PostPosted: Fri Apr 09, 2021 3:06 pm 
Offline

Joined: Thu Apr 08, 2021 12:39 pm
Posts: 3
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.'


Top
 Profile  
Reply with quote  
PostPosted: Mon Apr 12, 2021 8:06 am 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 644
Location: CCAA
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.

_________________
Best regards
Thomas
(Freelance Software Developer with several years of MigraDoc/PDFsharp experience)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group