MergeDocument.Draw does not close file when Exception is thrown

MergeDocument.Draw does not close file when Exception is thrown

Forum member · Feb 21, 2007
Hello, I'm using version 4.0.2.20 of the Merger library. I have noticed that the method MergeDocument.Draw does not close the destination file when an exception is thrown during the Draw method. Sample code: try { MergeDocument md = new MergeDocument(); // md has no pages => EmptyDocumentException md.Draw (@"C:\Temp\Document.pdf"); } catch (Exception) { } File.Delete (@"C:\Temp\Document.pdf"); The above code would throw an IOException with the message "C:\Temp\Document.pdf" in the last line. Is there a way to get around this problem? Will it be fixed in a future version? Thanks, Andreas

Re: MergeDocument.Draw does not close file when Exception is thrown

Forum member · Feb 21, 2007
Actually the message of the IOException will be "The process cannot access the file 'C:\Temp\Document.pdf' because it is being used by another process." Sorry, Andreas

Re: MergeDocument.Draw does not close file when Exception is thrown

Support · Feb 22, 2007
Hello Andreas, You will not be able to delete the file immediately. Once the garbage collector has done the cleaning you will be able to delete the file. In order to delete the file immediately, you will have to use the FileStream object and pass the FileStream to the Draw method. This will allow you to close the stream immediately and delete the file. Thanks, ceTe Software Support Team