Copy Word format into Outlook message

Posted by Jaster on Stack Overflow See other posts from Stack Overflow or by Jaster
Published on 2011-01-07T17:12:34Z Indexed on 2011/01/07 17:54 UTC
Read the original article Hit count: 186

Filed under:
|
|

Hi,

I have an outlook automation. I would like to use a Word document as template for the message content. Lets say i have some formatted text containing tables, colors, sizes, etc. Now I'd like to copy/paste this content into an Outlook message object.

I'm used to the interop stuff, i just have no idea how to copy/paste this correctly.

Here is some Sample Code (no cleanup):

        String path = @"file.docx";
        String savePath = @"file.msg";
        Word.Application wordApp = new Word.Application();
        Word.Document currentDoc = wordApp.Documents.Open(path);
        Word.Range range = currentDoc.Range(0, m_CurrentDoc.Characters.Count);
        String wordText = range.Text;

        oApp = new Outlook.Application();
        Outlook.NameSpace ns = oApp.GetNamespace("MAPI");
        ns.Logon("MailBox");
        Outlook._MailItem oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem);
        oMsg.To = "[email protected]";
        oMsg.Body = wordtext;
        oMsg.SaveAs(savePath);

Using Outlook/Word 2007, however the word files still mayb in 2000/2003 format (.doc).
Visual Studio 2010 with .net 4.0 (should obvious due to the samplecode).

Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about outlook