To add the contents to a folder:
- Create the items that will be added to the folder.
DKDDO * ddoDocument = dsICM->createDDO("book", DK_CM_DOCUMENT);
DKDDO * ddoFolder2 = dsICM->createDDO("book", DK_CM_FOLDER);
DKDDO * ddoItem = dsICM->createDDO("book", DK_CM_ITEM);
- Persist the created items to the datastore.
ddoDocument->add();
ddoItem->add();
ddoFolder2->add();
- Get the DKFolder attribute for the folder.
DKFolder * dkFolder;
short dataid = ddoFolder->dataId(DK_CM_NAMESPACE_ATTR,DK_CM_DKFOLDER);
if (dataid!=0) dkFolder =
(DKFolder*)(dkCollection*) ddoFolder->getData(dataid);
- Check out the folder.
Important: You do not need to lock an item before updating it if you are only
adding or removing links to the item without making any other changes
in the DDO. However, if you need to change anything else in the DDO,
such as modifying an attribute, you must checkout the item before
updating it.
dsICM->checkOut(ddoFolder);
- Add the created items to the folder.
dkFolder->addElement(ddoDocument);
dkFolder->addElement(ddoItem);
dkFolder->addElement(ddoFolder2); // Folders can contain sub-folders.
- Update the folder. This also checks in the
folder (unlocks it).
ddoFolder->update();
- Check in the folder.
dsICM->checkIn(ddoFolder);
Important: Alternatively, you can combine the checkin
request with your update call in Step 6 by using the DK_CM_CHECKIN(DKConstan.h) update option.