C# Interface into Microsoft Outlook Calendar?


R

Rico

From a C# program, how do I access my own Microsoft Outlook Calendar?

My ultimate goal is to add the information to my screen saver to
notify other employees where I am when not at my desk.

I assume the answer has something to do with an API (Application
Programmer Interface), but I've never used this one before.

Thanks.
 
Ad

Advertisements

R

Rico

Starting with this link:

http://stackoverflow.com/questions/90899/net-get-all-outlook-calendar-items

I tried the following code:

------------------------------- C U T - H E R E
-------------------------------

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder calendarFolder = null;

oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
calendarFolder = mapiNamespace.GetDefaultFolder
(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);

foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in
calendarFolder.Items)
{
System.Console.WriteLine(item.Location);
}

------------------------------- C U T - H E R E
-------------------------------

But get an exception at the start of the foreach loop:

System.InvalidCastException was unhandled

Message="Unable to cast COM object of
type 'System.__ComObject' to interface
type 'Microsoft.Office.Interop.Outlook.AppointmentItem'.

This operation failed because the QueryInterface call on the COM
component
for the interface with IID '{00063033-0000-0000-C000-000000000046}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

------------------------------- C U T - H E R E
-------------------------------

For whatever it's worth, I did put into AsssmelbyInfo.cs:

[assembly: ComVisible(true)]

but I still get the exception. Why?

Any ideas, please?
 
Ad

Advertisements

R

Rico

Starting with this link:

http://stackoverflow.com/questions/90899/net-get-all-outlook-calendar...

I tried the following code:

---------------- C U T - H E R E ----------------

Microsoft.Office.Interop.Outlook.Application oApp = null;
Microsoft.Office.Interop.Outlook.NameSpace mapiNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder calendarFolder = null;


oApp = new Microsoft.Office.Interop.Outlook.Application();
mapiNamespace = oApp.GetNamespace("MAPI");
calendarFolder = mapiNamespace.GetDefaultFolder
(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);


foreach (Microsoft.Office.Interop.Outlook.AppointmentItem item in
calendarFolder.Items)
{
System.Console.WriteLine(item.Location);
}


---------------- C U T - H E R E ----------------

But get an exception at the start of the foreach loop:

System.InvalidCastException was unhandled

Message="Unable to cast COM object of
type 'System.__ComObject' to interface
type 'Microsoft.Office.Interop.Outlook.AppointmentItem'.

This operation failed because the QueryInterface call on the COM
component
for the interface with IID '{00063033-0000-0000-C000-000000000046}'
failed due to the following error: No such interface supported
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

---------------- C U T - H E R E ----------------

For what it's worth, I did put into AsssmelbyInfo.cs:

[assembly: ComVisible(true)]

but I still get the exception. Why?

Any ideas, please?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top