Add new folder to root.

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.
 
A

Anthony Yio

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.
 
D

Dmitry Streblechenko \(MVP\)

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
 
A

Anthony Yio

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top