TestCaseTim

I need to import .msg and .pst containers into Outlook 2007 using c#. I am aware of the CreateFromTemplate method, but this alters the message by saving it as an unsent email. I want to import the message items into Outlook without modifying them, just like if I imported them manually through the UI. I don't know Extended MAPI and was trying to avoid using Redemption if possible. If these are my only options, then I will deal with them, but I was hoping there was a third option.

Does anybody have an example of some code, or know which methods I could use to accomplish this import using c# and the Outlook object model

Thanks!



Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

Sue Mosher - Outlook MVP

To add a .pst file to the current Outlook session, use AddStore or AddStoreEx.

To import an .msg file, use Namespace.OpenSharedItem, then call Save on the item that method returns.





Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

TestCaseTim

Sue,

Thanks for the help! I managed to get both to work, however I can't find a way to import (or move) the imported .PST file to the main "Mailbox - ..." store. When I use the following code:

Outlook._NameSpace olNs = outlookApplication.GetNamespace("MAPI");

Outlook._NameSpace mySession = (Outlook._NameSpace)outlookApplication.Session;

mySession.AddStore(@"C:\\Temp\\MyPst.pst");

it imports the pst as a new root level folder/store in outlook. Do you know what I need to do to store the pst into the Mailbox folder with all of the other default folders I have tried mySession.DefaultStore.Session.AddStore(@"C:\\Temp\\MyPst.pst"), but it appears to be the same thing above. I have tried to use the MAPIFolder.MoveTo function, but it would not move the folder. Any ideas

Thanks again.





Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

Sue Mosher - Outlook MVP

A .pst file and an Exchange mailbox are two completely separate types of data stores. Thus, there is no concept of storing a pst in a mailbox folder. Maybe you could provide more information on just what you're trying to do with this .pst file. Are you trying to move the data that the .pst file contains into corresponding folders in the Exchange mailbox





Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

TestCaseTim

That makes sense, and yes I am trying to move the contents of a .pst container on a local drive into a newly created folder in an Exchange mailbox. So would I have to open the pst as a shareditem and move each folder or item in that pst container to the Exchange mailbox folder one at a time with a copyto or moveto function

Thanks!





Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

Sue Mosher - Outlook MVP

Not quite: You would open the .pst file with AddStore or AddStoreEx, as I explained earlieer, then iterate its folders and copy each one with CopyTo into the mailbox, where they would become subfolders of the newly created target folder.





Re: Visual Studio Tools for Office How to Import a .msg and .pst file into Outlook 2007 with C# code?

TestCaseTim

Got it! Many thanks for your time and help Sue. You ROCK!