open .msg file using Process.Start()
Asked Answered
J

4

0
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

Jenijenica answered 16/2, 2015 at 4:5 Comment(0)
B
0

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();
Bauxite answered 16/2, 2015 at 4:36 Comment(2)
@Jenijenica Will you help me understanding what cases solution not handled, will try to improve it (if possible).Bauxite
you can try re-using the process (first) that you created and try to open another .msg file. it will open up another outlook. i'm looking for way(s) to avoid opening up another outlook.Jenijenica
J
0

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.

Jollify answered 16/2, 2015 at 13:23 Comment(2)
yeah the scenario here is that whenever i try to open an .msg file, it opens up another outlook 'window'. was wondering if there's a way to only open the .msg file and not an outlook window. does the CreateItemFromTemplate fit into my scenario here?Jenijenica
i'm thinking that it wouldn't fit as i'm just trying to open a .msg file and not storing it. i need a solution that allows me to open a .msg file without opening additional outlook windows.Jenijenica
C
0

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.

Chilly answered 16/2, 2015 at 14:51 Comment(0)
S
0

Just do it

var process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo
{
  FileName = fullPath //path of msg file
};
process.StartInfo = startInfo;
process.Start();
Snap answered 15/12, 2015 at 7:6 Comment(1)
How would that help? Outlook is a singleton, each time your open an MSG file, the control is transferred to the already running instance of Outlook, which will open another inspector window. There will be still just one instance of outlook.exe running.Chilly

© 2022 - 2024 — McMap. All rights reserved.