Exchange Web Service Managed Api - Save an email as an msg to disk


  • Hi,
    I am trying to save an email that I have retrieved via the EWS managed Api but get the following message when I try and open the file.

    "Cannot open file c:\bla\bin... The file may not exist, you may not have permission to open it, or it may be open in another program. Right-click the folder that contails the file, and then click Properties to check your permissions for the folder. "

    Any help will be much appriciated.

    See code below:

    public static void save_entire_email_to_disk()
        ExchangeService service = GetService();

        var findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(10));
        foreach (var result in findResults)
            if (result is EmailMessage)
                var message = result as EmailMessage;
                message.Load(new PropertySet(ItemSchema.MimeContent));
                MimeContent mc = message.MimeContent;
                FileStream oFileStream = new FileStream("Test.msg", FileMode.Create);

                oFileStream.Write(mc.Content, 0, mc.Content.Length);


    • Edited by Zi Makki Monday, September 07, 2009 2:45 PM Code looked BAD :(
    Monday, September 07, 2009 2:42 PM

All replies