问题
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. how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook?
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
回答1:
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();
回答2:
Only one instance of Outlook can be run at the same time.
how can i reuse the same process to open another .msg file without opening multiple processes/threads/instances of outlook?
You can use the Process.Start method to open the message in Outlook. There is no need to specify Outlook, only path to the .msg file.
Be aware, the Application class in Outlook provides you the CreateItemFromTemplate method. It creates a new Outlook item based on the specified template and returns the newly created Outlook item. You can use it to create an Outlook item based on the .MSG file. See How To: Create a new Outlook message based on a template for more information.
回答3:
If you want to close the already open Outlook messages, it is your responsibility to do so - use Application.Inspectors collection to enumerate all messages that Outlook is currently displaying and close them.
回答4:
Just do it
var process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
FileName = fullPath //path of msg file
};
process.StartInfo = startInfo;
process.Start();
来源:https://stackoverflow.com/questions/28534358/open-msg-file-using-process-start