0

I intend to open an outlook inbox page (see image) when the button is clicked. I use the code below but nothing happened. Hope to get some help

    private void button6_Click(object sender, EventArgs e)
    {
        Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application(); ;
        Microsoft.Office.Interop.Outlook.AppointmentItem appointmentItem = (Microsoft.Office.Interop.Outlook.AppointmentItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olAppointmentItem);
    }

enter image description here

masyita shariff
  • 110
  • 1
  • 8

3 Answers3

1

I managed to solve my own question. I didn't state in my original question but outlook app is already downloaded inside my laptop.

private void button6_Click(object sender, EventArgs e)
{
    Process.Start("outlook.exe");
}

Thanks to all of yall suggestions

masyita shariff
  • 110
  • 1
  • 8
0

I checked your code without an problem. So you need to track your error message of WindowsForm APP and confirm closed your Outlook. In general, you may getting the error about COM ID issue.

Please refer to the following links:

How to open Outlook new mail window c#

Code:

Outlook.Application oApp    = new Outlook.Application ();
Outlook._MailItem oMailItem = (Outlook._MailItem)oApp.CreateItem ( Outlook.OlItemType.olMailItem );
oMailItem.To    = address;
// body, bcc etc...
oMailItem.Display ( true );

Debug Error:

new Outlook.Application() thorws error if Outlook app is running

Simon Li
  • 303
  • 2
  • 4
  • Hi Simon, I've checked the link above and followed the _dcomcnfg_ thingy and I cannot find outlook message attachment, so maybe not a COM problem? Aactually my code above, once I pressed the button, there will be a pop-up at my taskbar stating: **Another program is using outlook. To disconnect program and exit outlook, click outlook icon and click exit now**. In reality, I did not open and outlook and when I checked control panel, outlook is also not running. – masyita shariff Nov 23 '18 at 06:17
  • Maybe some programs are using your Outlook, I think you need to check it. – Simon Li Nov 27 '18 at 07:08
0

Try something like the following (off the top of my head):

Outlook.Application oApp    = new Outlook.Application ();
Outlook.Namespace ns = oApp.GetNamespace("MAPI");
ns.Logon();
Outlook.MAPIFolder inbox = ns.GetDEfaultFolder(olFolderInbox);
if (oApp.Explorers.Count > 0)
{
  Outlook.Explorer expl = oApp.Explorers[1];
  expl.CurrentFolder = inbox;
}
else
{
  inbox.Display();
}
Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78