none
Outlook folder (created through code) not accessible in Outlook2013 in case of IMAP RRS feed

  • General discussion

  • I am developing a Outlook Addin . At the startup event i am creating a folder ("My Folder") under the Outbox folder and after that i try to find the number of mailitems inside this custom created folder "My Folder".

    Code Used:

    For creating folder:

     
    Outlook.Folder objFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
                    as Outlook.Folder;
                Outlook.Folders objFolders = objFolder.Folders;
                try
                {
                    if (objFolders.Count == 0)
                    {
                        Outlook.Folder objNewFolder = objFolders.Add("My FOlder", Type.Missing)
                            as Outlook.Folder;
                    }
                }
                catch (System.Exception ex)
                {
                    LogWriter.LogErrorMessage(ex);
                }

    For Accessing Folder Items:

                
                    string folderPath = Application.Session.DefaultStore.GetRootFolder().FolderPath + "My Folder";                Outlook.Folder objMyFolder = GetFolder(folderPath);


    GetFolder Method:

     
    private Outlook.Folder GetFolder(string strFolderPath)
            {
                Outlook.Folder folder;
                string backslash = @"\";
                try
                {
                    if (strFolderPath.StartsWith(@"\\"))
                    {
                        strFolderPath = strFolderPath.Remove(0, 2);
                    }
                    String[] arrFolders = strFolderPath.Split(backslash.ToCharArray());
                    folder = Application.Session.Folders[arrFolders[0]]
                        as Outlook.Folder;
                    if (folder != null)
                    {
                        for (int i = 1; i <= arrFolders.GetUpperBound(0); i++)
                        {
                            Outlook.Folders subFolders = folder.Folders;
                            folder = subFolders[arrFolders[i]]
                                as Outlook.Folder;
                            if (folder == null) { return null; }
                        }
                    }
                    return folder;
                }
                catch (System.Exception ex)
                {
                    LogWriter.LogErrorMessage(ex);
                    return null;
                }
            }

    The folder gets created successfully on Outlook.

    I am able to get the folder object objMyFolder in most of the scenarios but sometimes it gives error

    Exception:

    19/09/2014 10:32:16:ERROR:Exception message : The attempted operation failed.  An object could not be found.
    Exception Source : Microsoft Outlook
    Exception Trace  :    at Microsoft.Office.Interop.Outlook._Folders.get_Item(Object Index)
       at Project.ThisAddIn.GetFolder(String strFolderPath)
    Exception Target : Microsoft.Office.Interop.Outlook.MAPIFolder get_Item(System.Object)

    Note : I am able to access the folder object on all the machines where the mailaccount is using POP3 and in case of IMAP it gives the above exception.

    Please guide how to solve this error. I need to run this addin in all type of Outlooks irrespective of accounts and versions.

    Thanks In Advance


    • Edited by NitinRawat Friday, September 19, 2014 10:10 AM Removed unwanted things
    Friday, September 19, 2014 10:09 AM

All replies

  • Did you try to use any other provider, for example, Gmail?

    What string value is passed to the GetFolder method?

    Friday, September 19, 2014 12:50 PM
  • Why not store the folders' entry id and use Namesapce.GetFromFomId to open it?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    Friday, September 19, 2014 1:44 PM
  • I am asking for a possible reason of the error. Moving around is always a option but the question is why.

    Will be great if you can tell me some reason of the error.

    Friday, September 19, 2014 2:29 PM
  • it's something like "\\nitinr@mindfiresolutions.com\Outbox\Quatrix outbox".

    FYI the folder gets created properly and at the same path.

    Friday, September 19, 2014 2:30 PM
  • It looks like you forgot to answer my first question:

    Did you try to use any other provider, for example, Gmail? Does it work?


    Friday, September 19, 2014 2:46 PM
  • The issue may depend on the IMAP provider, not Outlook only. Did you have a chance to use a Gmail account instead? Does it work?
    Friday, September 19, 2014 2:48 PM
  • Hi Eugene

    Did not got chance to configure a gmail account . Will configure and will let you know the results.

    Meanwhile I read somewhere that if the newly created folder is not under any subfolder like Inbox, Outbox etc then it will not work but if it is present at the root level then it will work.

    So I changed my code of creating folder from

    Outlook.Folder objFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
                    as Outlook.Folder;

    To 

    Outlook.Folder objFolder = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox).Parent
                    as Outlook.Folder;

    and guess what it worked.

    They explained the reason that in IMAP the if created folder is under any sub folder then it is not synced to the outlook exchange server as opposite to POP3.

    I don't know the complete truth , will investigate it further. and yes will check in gmail too.


    • Edited by NitinRawat Friday, September 19, 2014 4:58 PM changed
    Friday, September 19, 2014 4:57 PM
  • Please let me know your results.
    Saturday, September 20, 2014 11:53 AM