Creating a Folder

  • Thread starter Thread starter Darren Kenneddy
  • Start date Start date
D

Darren Kenneddy

Whats the approved method for creating a new folder?

I can get the Default Contacts folder like so...

MAPIFolder pFldrContact;
pFldrContact = olNs.GetDefaultFolder(olFolderContacts);

but what do I do next to create a subfolder underneath
that folder??

Darren
 
Thanks Sue, but that doesn't translate to C++ at all. Most
of the problems I've come across when I here the VB
solution, I can figure it out in C++, but not this one.
Even with your help I can't seem to get my head around
this one. Is there anyone out there who's done this in C++?

Darren

-----Original Message-----
Same thing as with any collection -- use the Add method:

Set objNewFolder = pFldrContact.Folders.Add("New Folder Name")

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm


"Darren Kenneddy" <[email protected]> wrote in
message news:[email protected]...
 
Just to add some more to this.

The _Folders collection in C++ DOES have a .Add method.
However it is not accessible through MAPIFolder objects
and it is defined as:

LPDISPATCH _Folders::Add(LPCTSTR Name, const VARIANT& Type)

As you can see it requires not 1 but TWO parameters. The
string I assume is the name of the to-be-created folder,
but the Type?? It can't be olFolderType since that is
defined as type long, so what's supposed to go here?

Darren
 
Sorry I didn't recognize the C++ syntax. It's probably best to mention what language you're programming in or even include that in the subject of your posts.

Type should be one of the olFolderType constants. I don't know why it's showing up as Variant. Perhaps because it's optional (at least in VB/VBA/VBScript).
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm
 
No problem Sue. I looked up the VB call and see that yes
it does take two parameters and one is optional. The C++
version of the call though requires the second parameter,
so I guess I am left at a loss.

Anyone out there use the .Add method in C++???
Darren
-----Original Message-----
Sorry I didn't recognize the C++ syntax. It's probably
best to mention what language you're programming in or
even include that in the subject of your posts.
Type should be one of the olFolderType constants. I don't
know why it's showing up as Variant. Perhaps because it's
optional (at least in VB/VBA/VBScript).
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

"Darren Kennedy" <[email protected]> wrote in
message news:[email protected]...
 
Follow up....

Hello All,

I too am trying to create a new Contact folder in the Main Public Folder (root).
Weird cuz the code below works if I am in the contacts folder (creates a sub folder) but not in the Personal Folders...

I have created a COM Add-in and am using the OutlookApp object.

//Start a MAPI Session
m_spOutlookApp->get_Session(&olNs);
if(olNs == NULL)
return -1;

//Get the root of the personnals folder
CComQIPtr <Outlook::_Folders> spFolders;
CComQIPtr <Outlook::MAPIFolder> spNewFolder;
CComVariant varContItemType("IPF.Contact");//<-- This is the closest I got to getting it to work!
CComBSTR bstr_temp("CribeContacts");

olNs->get_Folders(&spFolders);
spFolders->Add(bstr_temp, varContItemType,&spNewFolder);//<--This does not work in personal folders but does in contacts folder

Any help would be greatly appreciated!
Chris
 
I'm not sure how to do it in C but normally you'd use the Folders.Add method
to add a new folder and set the Type argument to olFolderContacts. That
would automatically set the new folder as a Contacts folder.
 
Found IT !!

Ok after some messing around and a good night's sleep I finaly found out how to create new folders in the Personal Folders section of Outlook.

Hope this helps out other C++ developers out there cuz there aint much info on the net! :mad:

I found the IPF folder type thing on the msdn web site (god that site sucks, never a simple or clear example on there!)
http://support.microsoft.com/default.aspx?id=314192

----------

CComPtr <Outlook::_NameSpace> olNs;
CComQIPtr <Outlook::_Folders> spMainFolderList;
CComQIPtr <Outlook::_Folders> spPersonalFolderList;
CComQIPtr <Outlook::MAPIFolder> spPersonalFolder;
CComQIPtr <Outlook::MAPIFolder> spNewFolder;

//Folder type can be any of the following:
// STRFOLDERTYPE NAME
//----------------------------------
// MailItems IPF.Note
// ContactItems IPF.Contact
// AppointmentItems IPF.Appointment
// NoteItems IPF.StickyNote
// TaskItems IPF.Task
// JournalItems IPF.Journal
CComVariant varFolderType("IPF.Note");
CComBSTR bstr_temp("TestFolder");

//Start a MAPI Session
m_spOutlookApp->get_Session(&olNs);
if(olNs == NULL)
return -1;

//Get the folder list of the current session
olNs->get_Folders(&spMainFolderList);
//Get the first folder (this should be the Personal Folders)
spMainFolderList->GetFirst(&spPersonalFolder);
//Get the folder list of the Personal Folders folder
spPersonalFolder->get_Folders(&spPersonalFolderList);
//Add to the personal folder list.
spPersonalFolderList->Add(bstr_temp, varFolderType , &spNewFolder);
 
Back
Top