Cannot open/decrypt/encrypt .docx with password longer than 15 characters in .Net

﹥>﹥吖頭↗ 提交于 2019-12-11 04:07:09

问题


Problem

The following code works for .docx files with password upto 15 characters:

using Word = Microsoft.Office.Interop.Word;

var app = new Word.Application();
var doc = app.Documents.Open("file.docx", PasswordDocument: "<short password>");

For longer password the .Open method fails with COMExcetion of message: "Command failed".

Question(s)

With longer password, how can I:

  1. Encrypt/decrypt word files?

  2. Recognize that given password opens the file?

  3. (optionally) Open the file in Microsoft Word application programmatically?

Along with the links also sample code would be greatly appreciated.

Notes

  • Tried in all versions of Microsoft.Office.Interop.Word.dll: 12.0.0.0, 14.0.0.0 and 15.0.0.0

  • Spire.Doc seems to be solving points 1. and 2., but it is commercial and free version is pretty limited.

来源:https://stackoverflow.com/questions/27820525/cannot-open-decrypt-encrypt-docx-with-password-longer-than-15-characters-in-ne

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!