Closing document and then deleting the file=(File is in use)

PDF-XChange Viewer SDK for Developer's
(ActiveX and Simple DLL Versions)

Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange

adntES
User
Posts: 71
Joined: Fri Mar 25, 2011 5:43 pm

Closing document and then deleting the file=(File is in use)

Post by adntES »

Hi again team!, I have some weird problem here.

Here is an sample of the code :

Code: Select all

Private Sub frmPDFXViewer_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        Try

            AxPDFXviewer.CloseAllDocuments(PDFXCviewAxLib.PXCVA_Flags.PXCVA_NoUI)
            SupprimerPdfCourant()

        Catch ex As System.Runtime.InteropServices.COMException
            If System.Runtime.InteropServices.Marshal.GetHRForException(ex) = -2112683532 Then
                'Je laisse passer cette erreur puisque cela n'en devrai pas être une.
                'L'utilisateur a quitté le dialog pour imprimer

            ElseIf System.Runtime.InteropServices.Marshal.GetHRForException(ex) = -2081159993 Then
                'Je laisse passer cette erreur puisque cela n'en devrai pas être une.
                'L'utilisateur a quitté le dialog précis de l'imprimante choisi

            ElseIf System.Runtime.InteropServices.Marshal.GetHRForException(ex) = -2112673933 Then
                'aucun document n'est ouvert
                Me.Close()
            Else
                Throw New Exception(EasyDealChangeLanguage.Instance.GetStringFromResourceName("1271"), GetDetailComException(ex))
            End If
        Catch ex As Exception
            Throw ex
        End Try
In the SupprimerPdfCourant() i delete the file if it exist but i don't check if is in use because i assume that is it not, because
i closed the document.

However, i still got the error "cannot access file (in use)" when i try to delete the file..

I remark that if i enter in the debug mode and i browse the line
the error doesn't occur.Can the problem be at your side?? maybe the closing document function is just not closing fastly or doesn't freeing the document at 100%... Or Maybe is just that the process need to be on a waiting..

What do you think?
User avatar
Stefan - PDF-XChange
Site Admin
Posts: 19885
Joined: Mon Jan 12, 2009 8:07 am

Re: Closing document and then deleting the file=(File is in

Post by Stefan - PDF-XChange »

Hello AdntES,

I can't directly help in this case, but have passed it to the project leader for investigation and he will follow up on the topic.

Best,
Stefan
adntES
User
Posts: 71
Joined: Fri Mar 25, 2011 5:43 pm

Re: Closing document and then deleting the file=(File is in

Post by adntES »

Tracker Supp-Stefan wrote:Hello AdntES,

I can't directly help in this case, but have passed it to the project leader for investigation and he will follow up on the topic.

Best,
Stefan

Thanks!
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2445
Joined: Thu Jun 30, 2005 4:11 pm

Re: Closing document and then deleting the file=(File is in

Post by Vasyl - PDF-XChange »

Hi, adntES.

This problem can occur because closing of document file is asynchronous operation...
In the new build you will be able to use new feature:

Code: Select all

ctrl.SetDocumentProperty(docId, "SyncClose", "true", 0);
ctrl.CloseDocument(docId);
Currently, if you wanted to delete document file after closing use:

Code: Select all

ctrl.SetDocumentProperty(docId, "DeleteFileOnClose", "true", 0);
- and control will synchronous close and delete source file.

HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
adntES
User
Posts: 71
Joined: Fri Mar 25, 2011 5:43 pm

Re: Closing document and then deleting the file=(File is in

Post by adntES »

Vasyl-Tracker Dev Team wrote:Hi, adntES.

This problem can occurs because closing of document file is asynchronous operation...
In the new build you will be able to use new feature:

Code: Select all

ctrl.SetDocumentProperty(docId, "SyncClose", "true", 0);
ctrl.CloseDocument(docId);
Currently, if you wanted to delete document file after closing use:

Code: Select all

ctrl.SetDocumentProperty(docId, "DeleteFileOnClose", "true", 0);
- and control will synchronous close and delete source file.

HTH.
Thanks alot ! :D , however is this possible that the SaveDocument() function trigger the DeleteFileOnClose? My file is missing and i think is due to the save function.
User avatar
Vasyl - PDF-XChange
Site Admin
Posts: 2445
Joined: Thu Jun 30, 2005 4:11 pm

Re: Closing document and then deleting the file=(File is in

Post by Vasyl - PDF-XChange »

Hi, adntES.

If document.DeleteFileOnClose=="true" AND you saved the document to another file name THEN you will lose the original file - it is intended current behavior.

HTH.
PDF-XChange Co. LTD (Project Developer)

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.