Question

My application converts Microsoft Office documents into .XPS files.

I've successfully used Office Interop to convert Word, Excel and PowerPoint files. I can't figure out how to do the same for "Outlook Message Format (.msg)" files.

How can I do this?

Was it helpful?

Solution

You would first convert the MSG to DOC, HTML, or MHTML and then do a secondary conversion to XPS. There is no direct conversion support from MSG to XPS from within Outlook interop.

mailItem.SaveAs(targetDoc, Outlook.OlSaveAsType.olDoc); // convert MSG to DOC
// convert DOC as XPS
var wordDocument = wordApplication.Documents.Open(targetDoc);
if (wordDocument != null)
    wordDocument.ExportAsFixedFormat(targetXPS, 
        Word.WdExportFormat.wdExportFormatXPS, paramOpenAfterExport, paramExportOptimizeFor,
        paramExportOptimizeFor, paramExportRange, paramStartPage,
        paramEndPage, paramExportItem, paramIncludeDocProps, 
        paramKeepIRM, paramCreateBookmarks, paramDocStructureTags, 
        paramBitmapMissingFonts, paramUseISO19005_1,
        ref paramMissing);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top