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.

Mon Aug 31, 2020 9:07 am

Hello! :)

How can I Insert text from encrypted docx into another encrypted docx?

Example:
Initially there is loaded encrypted docx:
document.LoadFromFile("D:\main.docx", FileFormat.Docx, "password1")

then I need to insert text from another also encrypted docx
document.InsertTextFromFile("D:\part.docx", FileFormat.Docx)

but when using "InsertTextFromFile", there is no password string accepted...
document.InsertTextFromFile(D:\example.docx", FileFormat.Docx, "password2")

Is there any solution please?

Thank you.
T.

bt777_azet.sk
 
Posts: 12
Joined: Thu Apr 23, 2020 8:19 am

Mon Aug 31, 2020 9:47 am

Hello,

Thanks for your inquiry.
You can first remove the password of the file and then insert it into another file. Below is the code for your reference. If there are any questions, please feel free to write back.

Code: Select all
        Dim doc1 As Document = New Document
        doc1.LoadFromFile("main.docx", FileFormat.Docx, "password1")
        'remove the password of the file "part.docx"
        Dim doc2 As Document = New Document
        doc2.LoadFromFile("part.docx", FileFormat.Docx, "password2")
        Dim ms As MemoryStream = New MemoryStream
        doc2.SaveToFile(ms, FileFormat.Docx)
        'insert file
        doc1.InsertTextFromStream(ms, FileFormat.Docx)
        Dim output As String = "output.docx"
        doc1.SaveToFile(output, FileFormat.Docx2013)
        ms.Close()


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Aug 31, 2020 10:46 am

Thank you!

bt777_azet.sk
 
Posts: 12
Joined: Thu Apr 23, 2020 8:19 am

Tue Sep 01, 2020 1:11 am

Hello,

You are welcome.
If you encounter any issues related to our product in the future, just feel free to contact us.
Have a nice day!

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.Doc