Converting .msg files to tiff-Collection of common programming errors
I have a directory structure with in excess of 100,000 files in it, 20,000 of which are .msg files. I am looking to convert these files to .tif format and I am having difficulty in doing so.
First, please note that I only have Outlook 2003 on the machine and I am on Windows 7. My first inclination was to use the Outlook Interop, set the printer to ‘Office Document Image writer’ and use this to convert each .msg file to a tiff. I ran into 2 issues here; firstly I was unable to set the default printer to the ‘Office Document Image writer’ (I don’t think this is possible for Outlook, there is no method or property to do it; I can do it in the Word Interop) and secondly, I received an ‘unhandled’ exception below on attempting to open the msg using Session.OpenSharedItem().
(System.AccessViolationException: Attempted to read or write protected memory).
I know that my application has access to these folders, as I have successful read and converted other files (pdf, doc, xls) from the same location.
Anyone have any ideas on how I can go about converting these files to tif in C#? Note: I am using VS2008, Office 2003 and I can only use free software.
— More detail —-
Following on from the response here is some more detail.
Firstly, I am not familar with these .msg files at all. They are from some small associate company. From looking at about 50 or so of them, some contain no attachments and some contact pdf, Excel or Word attachments but I can’t go through all of them manually. I have been given the brief to ignore the attachments and just convert the mails to tif as they open in Outlook.
I see no property or method on the Outlook._Application to set the defaultprinter. I can set this in the Word and Excel interops but not for Outlook.
On code. The segment below demonstrates what I have been trying. I have added a reference to Microsoft.Office.Interop.Outlook version 14.0.0 and am attempting to open the .msg files and save them as a MS Word document using the code below. I am getting the ‘AccessViolationException’ exception above on calling OpenSharedItem.
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook._Application appOutlook = new Outlook.Application();
Outlook.MailItem oMsg = (Outlook.MailItem)appOutlook.Session.OpenSharedItem(@"D:\Test\test.msg");
oMsg.SaveAs(@"D:\Test\Mtest.doc", Outlook.OlSaveAsType.olDoc);