在保护模式下从c#打开Winword

在保护模式下从c#打开Winword,c#,ms-word,C#,Ms Word,有没有办法启动WinWord以打开文件 我没有使用Word Automation—只是启动文档,使Winword.exe从c#开始 这是密码 Process wordProcess = System.Diagnostics.Process.Start("C:\\\\check.docx");. 我应该添加什么来指示WinWord不正常打开文件,而是在文档顶部显示ProtectedView栏?Word 2010及更高版本 Word 2010及更高版本中存在一个动词,名为ViewProtected

有没有办法启动WinWord以打开文件

我没有使用Word Automation—只是启动文档,使Winword.exe从c#开始

这是密码

Process wordProcess = System.Diagnostics.Process.Start("C:\\\\check.docx");.
我应该添加什么来指示WinWord不正常打开文件,而是在文档顶部显示ProtectedView栏?

Word 2010及更高版本 Word 2010及更高版本中存在一个动词,名为
ViewProtected

string path = @"c:\path\to\file";
string file = "check.docx";

ProcessStartInfo psi = new ProcessStartInfo(Path.Combine(path, file));
psi.Verb = "ViewProtected";
Process wordProcess = System.Diagnostics.Process.Start(psi );
或者您可以使用命令行选项/vp

[path to winword.exe]\WinWord.exe  /vp  "c:\path\to\file\check.docx";
备选方案 对于早期版本,没有或谓词允许您在protectedmode中打开文件

您可以使用动词
OpenAsReadOnly
或使用一种变通方法,即复制原始文件并在打开之前将其标记为只读。以下代码演示了:

string path = @"c:\Your\Path\to\the\file";
string file = "check.docx";
// make copy
string tmp = Path.GetTempFileName().Replace(".tmp", Path.GetExtension(file));
File.Copy(Path.Combine(path,file), tmp );
// make it Read-Only
File.SetAttributes(tmp, FileAttributes.ReadOnly);
// Open the copy
Process wordProcess = System.Diagnostics.Process.Start(tmp );

wordProcess.EnableRaisingEvents = true;

// remove the file as soon as  the process ends
wordProcess.Exited += (o, args) =>
    {
        File.SetAttributes(tmp, FileAttributes.Normal);
        File.Delete(tmp);
    };

这是受保护的视图:ms word具有受保护的视图功能:。我的问题是:如何使用c#代码启动此功能。以前尝试过。但这还不够好。用户只有在试图保存或退出文件时才可以编辑文件(他这样做了)——他收到的是只读通知。受保护视图从一开始就禁用编辑…在Word 2010及更高版本中,动词ViewProtected exist可用于在受保护视图中打开文档