简体   繁体   English

使用Process.Start()打开.msg文件

[英]open .msg file using Process.Start()

ProcessStartInfo startInfo = new ProcessStartInfo();
Process first = new Process();   
startInfo.FileName = "OUTLOOK";
                    startInfo.Arguments = "http:\\blabla.com\EMAIL.msg";
                    startInfo.CreateNoWindow = true;                        
                    first.StartInfo = startInfo;
                    first.Start();

i used Process.Start to start up Outlook and open a .Msg file. 我使用Process.Start启动Outlook并打开.Msg文件。 how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook? 如何在不打开outlook的多个进程/线程/实例的情况下重用相同的进程来打开另一个.msg文件?

i have tried something like 我尝试过类似的东西

Process[] outlook = Process.GetProcessesByName("OUTLOOK");
Process existing = outlook[0];
                    startInfo.FileName = "outlook";
                    startInfo.Arguments = "http:\\blabla.com\2ndEMAIL.msg";
                    startInfo.CreateNoWindow = true;
                    existing.StartInfo = startInfo;
                    existing.Start();                         

to reuse the same process but i'm still opening multiple windows of outlook instead of just the .MSG file it 重用相同的进程,但我仍然打开outlook的多个窗口,而不仅仅是.MSG文件

Slightly modified your code, this might work. 略微修改您的代码,这可能会有效。

var first = new Process();
var pinfo = new ProcessStartInfo
            {
                FileName = "http:\\blabla.com\EMAIL.msg",
                Arguments = "/quiet",
                CreateNoWindow = true
            };
first.StartInfo = pinfo;
first.Start();

Only one instance of Outlook can be run at the same time. 只能同时运行一个Outlook实例。

how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook? 如何在不打开outlook的多个进程/线程/实例的情况下重用相同的进程来打开另一个.msg文件?

You can use the Process.Start method to open the message in Outlook. 您可以使用Process.Start方法在Outlook中打开邮件。 There is no need to specify Outlook, only path to the .msg file. 无需指定Outlook,只需指定.msg文件的路径。

Be aware, the Application class in Outlook provides you the CreateItemFromTemplate method. 请注意,Outlook中的Application类为您提供了CreateItemFromTemplate方法。 It creates a new Outlook item based on the specified template and returns the newly created Outlook item. 它根据指定的模板创建一个新的Outlook项目,并返回新创建的Outlook项目。 You can use it to create an Outlook item based on the .MSG file. 您可以使用它来创建基于.MSG文件的Outlook项目。 See How To: Create a new Outlook message based on a template for more information. 有关详细信息,请参阅如何:基于模板创建新的Outlook邮件

如果要关闭已打开的Outlook消息,则您有责任这样做 - 使用Application.Inspectors集合枚举Outlook当前显示的所有消息并关闭它们。

Just do it 去做就对了

var process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
  FileName = fullPath //path of msg file
};
process.StartInfo = startInfo;
process.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM