none
Iterating all contacts folders using VC++ RRS feed

  • Question

  • Hi All
    I am VC++ developer and trying to Automate Microsoft Outlook using VC++ and got stucked at one point so need your help indeed.

    Expecting your reply for my question.

    what i want to achieve through VC++ code is :-

    I have few contacts in my application and i want to transfer them to outlook. And in outlook itself there are 3 to 5 user created contacts folder.
    so first time i will ask user to pic the contact folder and once he chosen the contact folder, i will store the path of chosen contact folder in an .ini file
    So next time when he transfers the contact I will not ask him to choose the folder again via the same code, instead i will transfer the contact to the same old contact folder, whose path i have saved in the .ini file.

    so what i wanted to implement is to iterate all contact folders present in the outlook and get their path through pFolder->GetFullFolderPath(); function and compare it with saved path if found then i can use that folder object for moving my contact exactly there
    something like this
    pItem->Save();
    pItem->Move(pFolder);

    Partial Code snippet Below in VC++

    _ApplicationPtr pApp;
    _ItemsPtr pItems;
    MAPIFolderPtr pFolder, pFolderChld;
    _ContactItemPtr pContact;
    HRESULT hr;

    try
    {
    hr=pApp.CreateInstance(__uuidof(Application));

    if (FAILED(hr))
    {
    MsageBox("Unable to instantiate Outlook.","Outlook Error",MB_OK);
    return;
    }
    if(m_Option.GetCheck()) //default outlook contacts folder
    {
    pFolder=pApp->GetNamespace(_bstr_t("MAPI"))->GetDefaultFolder(olFolderContacts);
    if (pFolder==NULL)
    {
    MessageBox("Could not find default contacts folder.","Outlook Error");
    return;
    }
    }
    else //display folder selection window
    {
    pFolder = pApp->GetNamespace(_bstr_t("MAPI"))->PickFolder();
    if (pFolder==NULL)
    return;
    if (pFolder->GetDefaultItemType()!=olContactItem)
    {
    MessageBox("Select folder is not a Contact folder.","Outlook Contacts");
    return;
    }
    else
    {
    BSTR bsPath = pFolder->GetFullFolderPath();
    }

    Tuesday, December 18, 2012 6:07 AM

Answers

  • Why not remember the entry id of the folder (MAPIFolder.EntryID) after it is selected by the user, then the second time around just open the target folder using Namespace.GetFolderFromID?

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

    • Marked as answer by K.Anoop Tuesday, December 18, 2012 9:18 AM
    Tuesday, December 18, 2012 6:15 AM