none
Opening password protected Word file in FileStream RRS feed

  • Question

  • Hi,

    I have a password protected MS Word file (.doc). I have the password with me.

    How can I open the file in FileStream for reading purpose?

    Thanks,

    Hrushikesh


    Hrushikesh Pande

    Tuesday, August 8, 2017 6:39 AM

All replies

  • First you have to know how the structure is of that password and if there is an interop possibility to do that. 

    Therefore is a forum. Visual Studio for Office

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=vsto


    Success
    Cor

    Tuesday, August 8, 2017 7:36 AM
  • Hi,

    I have a read password protected MS Word file (.doc). I have the password with me.

    How can I open the file in FileStream for reading purpose?

    Thanks,

    Hrushikesh


    Hrushikesh Pande

    • Merged by Chenchen Li Thursday, August 24, 2017 8:51 AM duplicated
    Tuesday, August 8, 2017 8:06 AM
  • FileStream doesn't recognize Word document passwords. Just use Word automation and specify the password in the Document.Open command:

    http://burnignorance.com/vb-net-tricks/open-password-protected-word-document/


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Tuesday, August 8, 2017 5:20 PM
  • Hi Hrushi17,

    You can give the following solution a try, this solution is provided by a free word library available on Nuget.

    First, add reference to the dll. And then use the following code:

    Dim doc As New Document()
    
    'Load word file from FileStream with your password
    
    doc.LoadFromStream(filestream, FileFormat.Doc, "password")
    
    Dim sb As New StringBuilder()
    
    'Read the content in word file
    
    sb.Append(doc.GetText())


    Hope it helps.

    Wednesday, August 9, 2017 2:06 AM
  • Hi Hrushikesh,

    You asked the same question in here, some experts and I already gave you some answers, have you tried them :-)

    Wednesday, August 9, 2017 2:22 AM
  • oh... I thought I need to post the question to this forum so I posted here. Anyways... I will try the solution and will update the appropriate thread.

    Thanks. :)


    Hrushikesh Pande

    Wednesday, August 9, 2017 3:31 AM
  • Hi Hrushi17,

    By my search, I don't find any ways to open password protected word file in FileStream, but you can use the code below to open.

     Dim passwd As Object = "Password"
            Dim [readOnly] As Object = False
            Dim isVisible As Object = True
            Dim missing As Object = System.Reflection.Missing.Value
            WordApp = New Word.Application()
            Dim aDoc As Word.Document = WordApp.Documents.Open("D:\test\TestField.docx", missing, [readOnly], missing, passwd, missing,
        missing, missing, missing, missing, missing, isVisible)
    
            aDoc.Activate()
            WordApp.Visible = True

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, August 9, 2017 6:08 AM
    Moderator
  • Hi Hrushi17,

    Has your original issue been resolved? If it has, I would suggest you share your solution here and mark as answer to help other developer use this forum efficient. If not, please feel free to let us know your test result or your current issue. Thanks for understanding.

    Best Regards,

    Terry


    Friday, August 11, 2017 3:24 AM