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?