masyita shariff
masyita shariff

Reputation: 110

c# winforms: button to open outlook inbox page (outlook saved in computer)

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

Upvotes: 0

Views: 713

Answers (3)

masyita shariff
masyita shariff

Reputation: 110

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

Upvotes: 1

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

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();
}

Upvotes: 0

Simon Li
Simon Li

Reputation: 313

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

Upvotes: 0

Related Questions