none
How to save an Outlook item as msg file using C# RRS feed

  • Question

  • I am working on VSTO addin 2010 and 2007.

    Currently, I am using Extended MAPI to save the item as msg file. But i need to use Outlook Object Model in my code.

    I tried using OOM to save the file in Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSGUnicode format. But it doesn't seem to work.

    Is there any alternate way to do the same in C#?

    Tuesday, September 27, 2016 10:37 AM

All replies

  • Hello Saranya,

    What code exactly did you try?

    > But it doesn't seem to work.

    Could you please be more specific? Do you get any exception in the code?

    Anyway, make sure you specify fully qualified file name that includes the directory, filename, and extension.


    [custom.development]


    Tuesday, September 27, 2016 11:47 AM
  • >>>I tried using OOM to save the file in Microsoft.Office.Interop.Outlook.OlSaveAsType.olMSGUnicode format. But it doesn't seem to work.

    According to your description, have you gotten any exception? As far as I know that MailItem.SaveAs method saves the Microsoft Outlook item to the specified path and in the format of the specified file type. If the file type is not specified, the MSG format (.msg) is used.

    You could try to not specify file type as olMSGUnicode.

    In addition could you provide more information about your issue, for example sample code, exception and screenshot etc., that will help us reproduce and resolve it.

    Thanks for your understanding.
    Wednesday, September 28, 2016 3:27 AM
  • Hi David,

    I tried not to specify the file type as olMSGUnicode. The issue still persists.

    I found why the SaveAs method doesn't work. When i call the SaveAs method, the item is still busy, i.e. the item State is "Saving". That's why the SaveAs method throws exception saying "Exception has been thrown by the target of the invocation".

    Because the item is busy, I am not able to call the SaveAs method as well as Save method.

    Is there any other way to save the file ?

    Thanks in advance.

    Thursday, September 29, 2016 10:28 AM
  • Hi Eugene,

    I just call this. Item.SaveAs(filepath) where Item is my mail-item.

    I found why the SaveAs method doesn't work. When i call the SaveAs method, the item is still busy, i.e. the item State is "Saving". That's why the SaveAs method throws exception saying "Exception has been thrown by the target of the invocation".

    Because the item is busy, I am not able to call the SaveAs method as well as Save method.

    Is there any other way to save the file ?

    Thanks in advance.

    Thursday, September 29, 2016 10:32 AM
  • " the item is still busy, i.e. the item State is "Saving" - where does that come from? What is the exact exception when you call SaveAs? What is the relevant snippet of your code?

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Thursday, September 29, 2016 4:39 PM
  • Hi Saranya Madhusudhan,

    According to your description, I suggest that you could programmatically determine the current Outlook item to find out which type Outlook item is.

    For more information, please refer to How to: Programmatically Determine the Current Outlook Item

    In addition could you provide more information about your issue, for example sample code, screenshot etc., that will help us reproduce and resolve it.

    Thanks for your understanding.
    Tuesday, October 18, 2016 9:08 AM