0

我创建了一个 asp.net 应用程序,它具有将 Html 表转换为 Word 文档的一项功能。我已经成功地做到了这一点。但现在我需要用密码保护我的文件。是否可以通过添加密码使文件安全。我的转换代码如下所示。

Response.ClearContent();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", DateTime.Today.ToShortDateString().Replace("/", "").Replace("-", "") + "_" + DateTime.Now.ToShortDateString() + ".doc"));
        Response.ContentType = "application/ms-word";
        StringWriter sw = new StringWriter();
        HtmlTextWriter htw = new HtmlTextWriter(sw);

        tblMain.RenderControl(htw);

        string strPath = Request.PhysicalApplicationPath + "Test.doc";
        StreamWriter sWriter = new StreamWriter(strPath);
        sWriter.Write(sw.ToString());
        sWriter.Close();

如果有任何方法可以为保存文件添加密码,请帮助我。提前致谢..

4

2 回答 2

1

这是 C#,但看起来是您正在寻找的属性。

ThisDocument.SaveAs("c:\test\MyNewDocument.doc")

// C#
Object fileName = @"C:\Test\MyNewDocument.doc";
Object password = Type.Missing;
Object writePassword = Type.Missing;

ThisDocument.SaveAs(ref fileName, ref password, ref writePassword);

http://msdn.microsoft.com/en-us/library/office/aa192495(v=office.11​​).aspx

于 2013-03-28T05:06:09.813 回答
1

Word.Document 允许您通过将密码作为参数传递来保存文档。看到这个

于 2013-03-28T05:01:47.077 回答