Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 通过使用VSTO创建的MS word加载项打开内存中的word文档_C#_Vsto_Add In - Fatal编程技术网

C# 通过使用VSTO创建的MS word加载项打开内存中的word文档

C# 通过使用VSTO创建的MS word加载项打开内存中的word文档,c#,vsto,add-in,C#,Vsto,Add In,我一直在为Word编写外接程序。我将文档作为字节[]加载到内存中。我需要用Word打开它 using System.IO; public void MyWordFileReaderMethod() { string filePath = @"c:\example.docx"; var file = File.ReadAllBytes(filePath); } 对象文件将包含您需要的内容 编辑1 ProcessStartInfo startInfo = new Proces

我一直在为Word编写外接程序。我将文档作为
字节[]
加载到内存中。我需要用Word打开它

using System.IO;

public void MyWordFileReaderMethod()
{
   string filePath = @"c:\example.docx";
   var file = File.ReadAllBytes(filePath);
}
对象
文件
将包含您需要的内容

编辑1

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "WINWORD.EXE";
    startInfo.Arguments = @"c:\tempfile.docx";
    Process.Start(startInfo);

如果您需要用word启动内存文件,则只能将其放入临时文件并使用上面的代码。如果我没有弄错的话,两个进程无法跨进程边界共享数据。

如果您在硬盘上存储了一个文件,并且希望用MS Word打开它,那么为什么要将其加载到内存中。您可以使用Process类直接打开它

Process wordDoc = new Process();
wordDoc.FileName = @"c:\example.docx";
wordDoc.Start();

这是不可能的。Word无法从内存流打开文档。您必须使用(临时)文件。

我一直在为word编写外接程序。我把文件装入内存。我需要用Word打开它。你的问题不具体,有点让人困惑。Process类就是您要寻找的。将在一个小时内更新答案moment@Ateist答案已更新。无论我是否知道VSTO是无关的,您都不能在另一个进程上使用应用程序内存中的内容。它破坏了操作系统的所有安全标准。我的外接程序与Word在同一进程中运行。VSTO的知识仍然很重要。我从Web服务获取了一个字节[]的文件,不想保存。