Add new folder to root.

  • Thread starter Thread starter Anthony Yio
  • Start date Start date
A

Anthony Yio

Hello,

I am trying to add folder to the Personal Folders but it failed. It
could only add folder under my Default Mail , Task sub folder but not
directly under my root folder 'Personal Folder'

Below are my codes

BSTR senderName=NULL;

long lUnreadItemCount=0;

CComPtr<Outlook::MAPIFolder> spMAPIFolder;

CComPtr<Outlook::_Folders> spFolder;

CComPtr<Outlook::_Folders> spSubFolder;

CComPtr<Outlook::_Items> spItems;

CComPtr<Outlook::_NameSpace> spNameSpace;

CComPtr<Outlook::_DRecipientControl> spRecipientCtrl;


BSTR nameSpaceType = T2W("MAPI");

m_spApp->GetNamespace(nameSpaceType,&spNameSpace);

spNameSpace->GetDefaultFolder(olFolderInbox,&spMAPIFolder);

CComPtr<Outlook::_Folders> spTestFolder;

CComPtr<Outlook::MAPIFolder> spAddedMAPIFolder;

spMAPIFolder->get_Folders(&spTestFolder);

spTestFolder->Add(_bstr_t("TEST"), _variant_t((long)olFolderInbox),
&spAddedMAPIFolder); //this will work on add to folder under default mail
folder.


CComPtr<Outlook::MAPIFolder> spAddedSubFolder;

spFolder->Add(_bstr_t("TEST AGAIN"), _variant_t((long)olFolderJournal),
&spAddedSubFolder); //this will NOT work. Any pointers?



thanks in advance.
 
Sorry for the mess, below are the testing codes

CComPtr<Outlook::_Folders> spFolder;
CComPtr<Outlook::_NameSpace> spNameSpace;
CComPtr<Outlook::MAPIFolder> spAddedFolder;


BSTR nameSpaceType = T2W("MAPI");

//m_spApp is a CComPtr<Outlook::_Application> that initialize somewhere

m_spApp->GetNamespace(nameSpaceType,&spNameSpace);
spNameSpace->get_Folders(&spFolder);

spFolder->Add(_bstr_t("TESTAGAIN"), _variant_t((long)olFolderInbox),
&spAddedFolder);

//why is it that the TESTAGAIN folder is not added
//are there any rules apply by Outlook itself on
//creating a new folder under root?


thank you.
 
Namespace.Folders is not a real folder, but rather a collection of all top
level folders from all message stores in the current session.
To add a new PST store to the current profile, use Namespace.AddStore()
passing a fully qualified path to the PST file.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
thanks for the prompt reply.



Dmitry Streblechenko (MVP) said:
Namespace.Folders is not a real folder, but rather a collection of all top
level folders from all message stores in the current session.
To add a new PST store to the current profile, use Namespace.AddStore()
passing a fully qualified path to the PST file.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top