1
votes

I would like to create a folder under my username. I know how to do it under Inbox or under any other boxes. But how to create one next to the inbox, sent items and etc. Right now I have this code:

 {
            int Count = 0;
            Outlook.Application app = Globals.ThisAddIn.Application;
            Outlook.Folder folder = app.Session.GetDefaultFolder(
            Outlook.OlDefaultFolders.olFolderInbox) as Outlook.Folder;
            Outlook.Folders folders = folder.Folders;
            Regex FolderCheck = new Regex("MyFolder1");


            foreach (Outlook.Folder folder1 in folders )
            { 

                Count += FolderCheck.Matches(folder1.Name).Count;
            }
            try
            { 
                if (Count == 0)
                {
                    Outlook.Folder PRISKaust = folders.Add("MyFolder1", Type.Missing) as Outlook.Folder;
                    Outlook.Folders PrisKaustSees = PRISKaust.Folders;
                    Outlook.Folder INPRIS1 = PrisKaustSees.Add("MyFolder2", Type.Missing) as Outlook.Folder;


                }
            }
            catch
            {
                MessageBox.Show(
"Error apeared in creating folder", "Folderite Lisamine",
                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

It creates MyFolder1 under Inbox. And MyFolder2 under the Myfolder1. But the path needs to be like this: [email protected]/MyFolder1/MyFolder2

Please help.

1

1 Answers

2
votes

Retrieve the Inbox folder like you do now, but use MAPIFolder.Parent.Folders.Add. The parent of the Inbox folder is the top IPM folder in the store.