\nMS article: http://support.microsoft.com/kb/257757
\n","author":{"@type":"Person","name":"w3dev"},"upvoteCount":1}}}Reputation: 555
I just created a C# Desktop application for my personal use which reads my outlook calendar using Office.Interop
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?
Code:
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(
Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderCalendar);
calendarItems = folder.Items;
foreach (
Microsoft.Office.Interop.Outlook.AppointmentItem item in calendarItems)
{
// process item
}
Upvotes: 1
Views: 4171
Reputation: 555
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/kb/257757
Upvotes: 1