4

I'm writing piece of code which will handle extraction of information from email stored in *msg Outlook file. The idea how to do it I took from C# Outlook interop and OpenSharedItem for opening MSG files. But when calling method OpenSharedItem a get such error System.AccessViolationException. Anyone know what's the problem?
Here is code causing error

Outlook._Application app = new Outlook.Application();
Outlook.NameSpace NS = app.GetNamespace("MAPI");
Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
Outlook.MailItem fld =  (Outlook.MailItem) app.Session.OpenSharedItem("E://Projects//C#//message1.msg");
Community
  • 1
  • 1
pchot
  • 380
  • 3
  • 14
  • I think this can be due to version of Outlook. Somewhere I found that it works only since Outlook 2007. Anyone can confirm? – pchot Apr 25 '11 at 22:08

1 Answers1

8

Ok. In case anybody will face the same problem finally I've got an answer. First of all should be

Outlook.MailItem fld =  (Outlook.MailItem) app.Session.OpenSharedItem("E:\\Projects\\C#\\message1.msg");

difference is in the slashes.
Then all you need to make it work is Outlook 2007 or newer. And that's it :]

pchot
  • 380
  • 3
  • 14