Asanka sanjaya Asanka sanjaya - 1 year ago 184
C# Question

Outlook Redemption - eml to pst - Specify folder Hiarachy

I'm using Outlook redemption( and following C# code to generate a PST file from .eml files.

RDOSession session = new RDOSession();
RDOPstStore store = session.LogonPstStore(newpstpath);
RDOFolder folder = store.IPMRootFolder.Folders.Item(directoryEmlFile);
if (folder == null)
folder = store.IPMRootFolder.Folders.Add(directoryEmlFile);

RDOMail mail = folder.Items.Add("IPM.Note");
mail.Import(directoryEmlFile + "\\0a53e310-b841-43bf-9586-8e7ddb4cd175" + ".eml");
mail.Sent = true;

It creates a PST file but when I import it to outlook the folder structure is similar to this.

Personal Folders

Inside C:\Users\asanka\eml folder I can see the imported email. That is the folder where .eml file was originaly located. I need to get rid of that and have the folder structure like this.

Personal Folders

How can I do that? any help is appreciated.

Answer Source

That is the folder name you are passing to Folders.Add, right? You need to pass the appropriate name (asanka) to create the folder. You will probably need to do that twice since you have two folders:

RDOFolder folder1 = store.IPMRootFolder.Folders.Item("asanka");
if (folder1 == null) folder1 = store.IPMRootFolder.Folders.Add("asanka");
RDOFolder folder = folder1.Folders.Item("Inbox");
if (folder == null) folder = folder1.Folders.Add("Inbox");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download