w3dev w3dev - 5 months ago 122
C# Question

Using Outlook Office.Interop from a C# windows service

I just created a C# Desktop application for my personal use which reads my outlook calendar using

libraries and posts all items to the Google calendar. It worked fine until I tried to convert it to a windows service. It always throws following error:

The file E:\...\Outlook Data File.pst cannot be opened.

I tried with different user accounts, but nothing worked. At the same time, the desktop application works as expected. Any idea?


Microsoft.Office.Interop.Outlook.Application application = null;
Microsoft.Office.Interop.Outlook.NameSpace applicationNamespace = null;
Microsoft.Office.Interop.Outlook.MAPIFolder folder = null;
Microsoft.Office.Interop.Outlook.Items calendarItems = null;

application = new Microsoft.Office.Interop.Outlook.Application();
applicationNamespace = application.GetNamespace("MAPI"); ;
folder = applicationNamespace.GetDefaultFolder(
calendarItems = folder.Items;

foreach (
Microsoft.Office.Interop.Outlook.AppointmentItem item in calendarItems)
// process item

Answer Source

It seems that Interop is not supported in an unattended, non-interactive application:

Related Stackoverflow answer: https://stackoverflow.com/a/13480267/1716736
MS article: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download