none
Office 2007 Documents Removing Encryption Urgent !!!!!!!!!!!!! RRS feed

  • Question

  •  Hi ,

      My application demands sending  encrypted password protected docx , xlsx files through email and We need to recieve it and write it on the disk and remove password protection so that it can be accessable to all users .

    In the sending part i am encrypting the doc using the below code

    Microsoft.Office.Interop.Word.Document newDoc = new Microsoft.Office.Interop.Word.Document() ;
    /// Some code 
     newDoc.SaveAs(filePath, Type.Missing, Type.Missing, "Password", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    ///Some code
    
    ///Send mail with attached password protected document
    

    In the recieving side I need to remove the encryption . How can I remove encryption using c# code

    I tried ,

    Word.Document wordDoc = null; 
    
    wordDoc = WordApplication.Documents.Open(filePathDocument, Type.Missing, Type.Missing, Type.Missing, "Password", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, false, Type.Missing, Type.Missing, Type.Missing, Type.Missing); 
    wordDoc .SaveAs(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    


    and I tried the unprotect method .. they are not seems to be working

    any help will be appreciated



    • Edited by VSTO Keen Thursday, October 13, 2011 6:12 AM
    • Moved by Cindy Meister MVPModerator Thursday, October 13, 2011 12:46 PM Word-specific (From:General Office Development)
    Thursday, October 13, 2011 6:10 AM

Answers

  • Hi VSTO Keen,

    Thanks for your post.

    When you save the word document again, please set the wordDoc.Password="". Please try below code and let us know the situation on your side.

    wordDoc.SaveAs("D:\testmodify.docx", Type.Missing, Type.Missing, "", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
    

    If you have any concerns, please feel free to follow up.

    Have a nice day.

    Best regards


    Liliane Teng [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by VSTO Keen Friday, October 14, 2011 3:53 PM
    Friday, October 14, 2011 9:59 AM