public static void EncryptWithPassword(string unEncryptedWordPath, string password)
{
Word.Application wordApp = null;
Word.Document document = null; try
{
object missung = System.Type.Missing;
object odocPath = unEncryptedWordPath;
object opassword = password; wordApp = new Word.Application();
document = wordApp.Documents.Open(odocPath);
document.Password = password;
document.SaveAs(ref odocPath, Word.WdSaveFormat.wdFormatDocumentDefault);
}
catch (Exception e)
{
string s = e.ToString();
Console.WriteLine(s);
throw;
}
finally
{
Quit(wordApp, document);
}
} public static void Quit(Word._Application wordApp, Word._Document doc)
{
if(doc != null)
((Word._Document)doc).Close(Word.WdSaveOptions.wdDoNotSaveChanges);
object ofalse = false;
//ref false to prevent the Word Process Hang in Task Manager
if(wordApp !=null && wordApp.Application != null)
((Word._Application)wordApp.Application).Quit(ref ofalse, ref ofalse, ref ofalse);
}

  

c# word interop encrypt with password protect with password的更多相关文章

  1. MySQL加入服务、设置password、改动password

    修正:加入MySQL服务时,能够不带版本.也就说以下的全部MySQL57能够直接写成MySQL!希望大家注意. MySQL安装好之后,往往还须要再做一些设置! 1.加入MySQL服务: 输入命令cmd ...

  2. Password Management:Hardcoded Password 密码管理:硬编码密码

  3. Fortify漏洞之Dynamic Code Evaluation: Code Injection(动态脚本注入)和 Password Management: Hardcoded Password(密码硬编码)

    继续对Fortify的漏洞进行总结,本篇主要针对  Dynamic Code Evaluation: Code Injection(动态脚本注入) 和 Password Management: Har ...

  4. C# Protect the Password inside a TextBox ZZ

    If the Text property is called, it will send an WM_GETTEXT message, so it will surely be an internal ...

  5. 密码硬编码(Password Management: Hardcoded Password)

    在对项目进行安全扫描时,发现一些密码硬编码问题,本文主要三个方面:1)什么是密码硬编码:2)密码硬编码的危害:3)密码硬编码的解决方案. 一 什么是密码硬编码 将密码以明文的形式直接写到代码中,就是密 ...

  6. webshell 生成工具 b374k

    还在为不会写webshell而感到心累?还在为webshell有后而不敢用?? b374k,我们首先去github下载b374k https://github.com/b374k/b374k.git ...

  7. 在C#中使用Spire.doc对word的操作总结

    在C#中使用Spire.doc对word的操作总结 在最近的工程中我们要处理一些word文档.通过在网上的大量搜索,我发现大多数软件功能不是不完整就是有重复.极少数可以完全实现的word组件又要收费. ...

  8. C#操作Word文档(加密、解密、对应书签插入分页符)

    原文:C#操作Word文档(加密.解密.对应书签插入分页符) 最近做一个项目,客户要求对已经生成好的RTF文件中的内容进行分页显示,由于之前对这方面没有什么了解,后来在网上也找了相关的资料,并结合自己 ...

  9. (转)C#操作Word文档

    原文1地址:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 原文2地址: http://www.cnblogs.com ...

随机推荐

  1. [原][杂谈]如果人类的末日:"天网"出现

    本文由南水之源在2019年3月21日发布,转载需声明原作者 本文仅为一次基于科技发展与科幻小说的幻想,如果天网真的出现,请不要参考这篇逻辑破败的推论. 参考: 天网(Skynet),是电影<终结 ...

  2. UI组件--element-ui合计行在横向滚动条下面的解决方法

    使用element-ui合计功能, 因列数较多, 产生横向滚动条: 但是合计行却在滚动条下面, 拖动滚动条合计行不会跟着横向滚动. 在当前页面添加以下样式: <style lang='less' ...

  3. visual studio常用技法相关

    (1)查看dll里面包含了那些函数(dumpbin是visual studio内置工具)dumpbin -exports user32.lib (2)#include "stdlib.h&q ...

  4. sublime text3使用

    设置tab键为若干空格 { "tab_size": 4, "translate_tabs_to_spaces": true }

  5. 树中的路径和 Sum of Distances in Tree

    2019-03-28 15:25:43 问题描述: 问题求解: 写过的最好的Hard题之一. 初看本题,很经典的路径和嘛,dfs一遍肯定可以得到某个节点到其他所有节点的距离和.这种算法的时间复杂度是O ...

  6. NetSec2019 20165327 Exp3 免杀原理与实践

    NetSec2019 20165327 Exp3 免杀原理与实践 pre基础问题回答 一.免杀原理 一般是对恶意软件做处理,让它不被杀毒软件所检测.也是渗透测试中需要使用到的技术. 要做好免杀,就时清 ...

  7. 初学spring笔记

    简单hello world 项目,了解IOC 反转控制

  8. python-作用域解析

    局部作用域和全局作用域:局部作用域不能修改全局作用域的变量 count = 10 def outer(): #global count 局部变量改成全局变量,global声明一下即可.就可以修改了. ...

  9. koa源码之delegate使用

    koa中context可以直接调用request和response属性的重要原因是使用了delegate将req和res的属性代理到context, Delegator.prototype.gette ...

  10. 开发者的自测利器-Hprof命令(寻找cpu热点)

    测试代码: public class HProfTest { public void slowMethod() { try { Thread.sleep(1000); } catch (Excepti ...