Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Fri Jan 19, 2018 4:37 am

Hello,

I'm trying to see if your software can help me open up DOC/DOCX files. Some files are passworded, and I do not know which files they are, so I need to handle them.

This is my code:

Code: Select all
        Dim doc As Document
        Try
            doc = New Document(fileName)
            'if this works, do something...
        Catch ex As Exception
            If ex.Message = "Document is encrypted, Open the password needs password." Then
                      'the file is password protected
                      'do something else...
            End If
        Finally
            doc = Nothing
        End Try


The problem is, no matter what I try, the file remains *locked* (on the filesystem). I cannot release the lock to the file, so the file cannot be renamed or deleted until I terminate the application. Any thoughts? I'm using your latest version, free for now. Thank you.

hades_2101
 
Posts: 3
Joined: Fri Jan 19, 2018 4:03 am

Fri Jan 19, 2018 7:25 am

Hello,

Thanks for your inquiry. I have tested the case but it can work fine on my side, the following is my test codes. If you can share us a runable application that shows the issue, it would be helpful to look into the issue.
Code: Select all
   Private Sub Test(fileName As String)
        Dim doc As Document
        Try
            doc = New Document(fileName)
            'if this works, do something...
        Catch ex As Exception
            If ex.Message = "Document is encrypted, Open the password needs password."  Then
                System.IO.File.Delete(fileName)
            End If
        Finally
            doc = Nothing
        End Try
    End Sub

Sincerely,
Gary
E-iceblue support team
User avatar

Gary.zhang
 
Posts: 1380
Joined: Thu Apr 04, 2013 1:30 am

Fri Jan 19, 2018 11:38 pm

Thank you for the very quick response. Attached is a working snippet of the program. Some observations:

1) I can open non-passworded documents just fine.
2) If I open a passworded document, like "pass.doc" in the attached file, I get an exception thrown: "{"Document is encrypted, Open the password needs password."}", which is understandable. However, when the application runs through, the file remains locked and cannot be deleted from the filesystem (explorer). Tells me "File in use".
3) If I open a passworded document, like "pass.docx" in the attached file, I get an exception thrown: "{"Destination array was not long enough. Check destIndex and length, and the array's lower bounds."}", which is ????

Cannot upload files to your forum, so have placed the code here:
/s/j5lkvk6dl4dl9py/DOCTest.7z?dl=0

Thank you.

EDIT: I can't upload files to your forum. Nor can I share URLs. The above link is a dropbox link. please stick dropbox.com before it.

hades_2101
 
Posts: 3
Joined: Fri Jan 19, 2018 4:03 am

Mon Jan 22, 2018 8:36 am

Hello,

Thanks for your sharing. Please update to the latest version(Spire.Doc Pack(hot fix) Version:6.1.12) which doesn't have the issues you mentioned and try again.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Tue Jan 23, 2018 6:46 am

Hello,

Thank you very much for the quick fix. I tested it out, and although the exception thrown is different for passworded DOC and DOCX files, it's not a problem. I was able to handle passworded DOC/DOCX files, and the files on the file-system are not locked. Much appreciated!

I will now go back and update the main program. I have only done testing in the little program I shared here. Thanks.

hades_2101
 
Posts: 3
Joined: Fri Jan 19, 2018 4:03 am

Tue Jan 23, 2018 7:02 am

Hello,

Thanks for your feedback. If you encounter any other question, please get it back to us. Have a good day.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Thu Jan 25, 2018 6:33 am

Hello,

Greeting from E-iceblue.
Did you try the hotfix with your main program? How is it going?
Your feedback will be greatly appreciated.

Best regards,
Simon
E-iceblue support team
User avatar

Simon.yang
 
Posts: 620
Joined: Wed Jan 11, 2017 2:03 am

Return to Spire.Doc