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. julia 安装

    https://julialang.org/downloads/ 下载安装程序,拖拽完成安装

  2. flex:1详解(转)

    转载自:https://blog.csdn.net/fengyjch/article/details/79047908 flex 是 flex-grow.flex-shrink.flex-basis的 ...

  3. C语言的三目运算符

    语法: 表达式1 ? 表达式2 : 表达式3; 等价于 if(表达式1) { 表达式2 } else { 表达式3 }

  4. [Linux]最新sublime text 3显示图标

    sublime text 3显示图标 执行命令 sudo vim /usr/share/applications/sublime_text_3.desktop 添加相应信息 [Desktop Entr ...

  5. 【转】 glibc detected *** corrupted double-linked list:错误的原因有如下三种可能

    一个多线程的大程序运行的时候崩掉了,屏幕上打出这个:   *** glibc detected *** corrupted double-linked list: 0xb78381d8 *** 三个原 ...

  6. SpringBoot之AOP

    AOP:面向切面编程,相当于OOP面向对象编程. Spring的AOP的存在目的是为了解耦,AOP可以让一组类共享相同的行为. Spring支持AspectJ的注解切面编程: (1)使用@Aspect ...

  7. 【堆】【洛谷例题】p1090 p1334 p1177

    (都是比较简单的典型的而且都是小根堆的例题) p1090 合并果子[传送门] 算法分析:要尽量使用最小的体力合并完所有果子,那么每次合并的两堆果子应该是这所有堆中最小的一个(因为越先合并的堆要被算的次 ...

  8. Appium TestNg Maven Android Eclipse java自动化环境搭建

    1.环境准备 1)Eclipse + maven + appium + TestNg 确保已经在Eclipse 上面安装maven TestNg的插件 2)打开Eclipse,新建一个maven项目 ...

  9. RTX腾讯通字体全变成横着的了

    呵呵,简单,RTX字体选择里边的字体列表中同一种字体有些是带@符号的,有些没有带,记着选不带@号的就是头朝上的了.

  10. C++标准模板库(STL)之Queue

    1.Queue的常用用法 queue:队列,实现的一个先进先出的容器. 1.1.queue的定义 使用queue,首先要加头文件#include<queue>和using namespac ...