Purchase your Section 508 Compliance Support guide now!

Purchase your Section 508 Compliance Support guide now!

Cognos 8 SDK -- add new folder

private void createNewFolder(String newFolderName)
{
propEnum[] properties = new propEnum[]{propEnum.searchPath, propEnum.defaultName};

addOptions add = new addOptions();
add.updateAction = updateActionEnum.replace;

//create new folder object
folder aFolder = new folder();

tokenProp tp = new tokenProp();
tp.value = newFolderName;

aFolder.defaultName = tp;

searchPathMultipleObject searchPath = new searchPathMultipleObject();
searchPath.Value = "/content/folder[@name='" + newFolderName + "']";

try
{
baseClass[] folder = cmService.query(searchPath, properties,new sort[] {},new queryOptions());
// Check if the folder is already exist if not create it.
if (folder.Length == 0)
{
searchPathSingleObject searchPathSing = new searchPathSingleObject();
searchPathSing.Value = "/content";
cmService.add(searchPathSing,new baseClass[]{aFolder},add);

Console.WriteLine("New folder [" + newFolderName +"] has been created.");
}
else
{
Console.WriteLine(newFolderName + " is already exist.");
}
}
catch(Exception e)
{
Console.WriteLine("Exception " + e.Message.ToString());
}
}