Search code examples
c#outlookoutlook-redemption

Outlook Redemption - eml to pst - Specify folder Hiarachy


I'm using Outlook redemption(http://www.dimastr.com/redemption/home.htm) 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;
            mail.Save();
            store.Save();

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

Personal Folders
  -C:\Users\asanka\eml

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
  -asanka
    -inbox

How can I do that? any help is appreciated.


Solution

  • 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");