PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Oct 15, 2019 11:26 pm

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sat Jul 20, 2019 11:27 am 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 21
When the PDF file has been created and is still open in Adobe Reader an exception error occurs.
Here is the stack Trace:
Quote:
System.IO.IOException
HResult=0x80070020
Message=The process cannot access the file 'D:\Visual Basic Projects\My Greeting\My Greeting\bin\Debug\Verse.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)
at PdfSharp.Pdf.PdfDocument.Save(String path)
at My_Greeting.frmPrintFrm.printIt(DataRow row) in D:\Visual Basic Projects\My Greeting\My Greeting\frmPrintFrm.vb:line 156
at My_Greeting.frmPrintFrm.btnPrint_Click(Object sender, EventArgs e) in D:\Visual Basic Projects\My Greeting\My Greeting\frmPrintFrm.vb:line 97
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at My_Greeting.My.MyApplication.Main(String[] Args) in :line 81

Karen @ MDSN suggested adding line: document = Nothing
But this did not solve it.
Had an idea of creating a For Next loop to add a number to the filename, but iterated all the range before leaving the form.
Can you advise a method to cure this problem?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 21, 2019 10:57 pm 
Offline
PDFsharp Expert
User avatar

Joined: Sat Mar 14, 2015 10:15 am
Posts: 481
Location: CCAA
Rocky48 wrote:
Can you advise a method to cure this problem?
Not a problem, everything working as intended.

To improve the usability, you can add a GUID to the filename like some PDFsharp/MigraDoc samples do.
http://www.pdfsharp.net/wiki/MixMigraDo ... ample.ashx

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 26, 2019 7:37 pm 
Offline

Joined: Fri May 03, 2019 10:10 pm
Posts: 21
I fixed it very simply by creating a random number between 1 and 100000 and concatinating this into the filename.
Problem solved!


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

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 404 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