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");
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 :]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With