none
Session.OpenSharedItem for opening .MSG files showing Error in Outlook C# RRS feed

  • Question

  • Hai, I am using the following code to open the signed/unsigned outlook messages. and i display the content in webbrowser control.

     Microsoft.Office.Interop.Outlook.Application app = new Microsoft.Office.Interop.Outlook.Application();

                        var item = app.Session.OpenSharedItem(msgfile) as Microsoft.Office.Interop.Outlook.MailItem;
                        string message = item.HTMLBody;
    app.Session.Logoff();     

    it's working fine for the first time the file is opening.but after closing the outlook file trying to reopen the file it showing the following error

    "Cannot open file: C:\tion.msg. 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 contains the file, and then click Properties to check your permissions for the folder."

    after some time later it's opening fine. For this strange behavior what could be the reason and how to rectify the that Error message.

    Thank you.


    V G S Naidu

    Monday, January 21, 2013 1:29 PM

Answers

  • as long as you do not call save on mailitem, this item should be temporary on outlook and you should not worry about that. Your main concern is to make outlook process _really_ exit after your code is done with it - so, make changes to your code that manipulates outlook that after you call Quit on app and call Marshal.FinalReleaseCOMObject on it, outlook process disappears from task manager.
    • Marked as answer by V G S Naidu Wednesday, January 23, 2013 4:01 AM
    Tuesday, January 22, 2013 9:14 AM

All replies

  • outlook process is still hanging around - very this using task manager. To close outlook process, call .Quit() on it and release all COM objects that you obtained, here app, item, session.
    Monday, January 21, 2013 1:40 PM
  • Eventhough i released the COM Objects, it showing the same error as like above.

    "Cannot open file: C:\tion.msg. 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 contains the file, and then click Properties to check your permissions for the folder."

    After some time it works well.In this point of time what i have observed  is that, when i open the Mailitem it creates a copy of the Outlook Message in my outlook Inbox folder and it stays for some time there, after closing the program and in the right bottom of the taskbar on my desktop it showing the Outlook Icon with settings icon on it.

    Then when i delete the message in my outlook manually and running the program works fine.

    How can i programatically delete the particular tempararely saved message in outlook ?

    Thank you.

     


    V G S Naidu

    Tuesday, January 22, 2013 5:46 AM
  • as long as you do not call save on mailitem, this item should be temporary on outlook and you should not worry about that. Your main concern is to make outlook process _really_ exit after your code is done with it - so, make changes to your code that manipulates outlook that after you call Quit on app and call Marshal.FinalReleaseCOMObject on it, outlook process disappears from task manager.
    • Marked as answer by V G S Naidu Wednesday, January 23, 2013 4:01 AM
    Tuesday, January 22, 2013 9:14 AM
  • Thank you very Much for your valuable answers.


    V G S Naidu

    Wednesday, January 23, 2013 4:00 AM