Kentico CMS 6.0 Developer's Guide

Managing web part categories

Managing web part categories

Previous topic Next topic Mail us feedback on this topic!  

Managing web part categories

Previous topic Next topic JavaScript is required for the print function Mail us feedback on this topic!  

Arrow


API examples for newer versions


Please visit the latest API Examples documentation to view API examples for newer versions of Kentico.



The following example creates a web part category.

 

private bool CreateWebPartCategory()
{

  WebPartCategoryInfo root = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("/");

 
    if (root != null)
    {
        // Create new web part category object
        WebPartCategoryInfo newCategory = new WebPartCategoryInfo();
 
        // Set the properties
        newCategory.CategoryDisplayName = "My new category";
        newCategory.CategoryName = "MyNewCategory";
        newCategory.CategoryParentID = root.CategoryID;
 
        // Save the web part category
        WebPartCategoryInfoProvider.SetWebPartCategoryInfo(newCategory);
 
        return true;
    }
 
    return false;
}

 

The following example gets and updates a web part category.

 

private bool GetAndUpdateWebPartCategory()
{

  // Get the web part category
  WebPartCategoryInfo updateCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

    if (updateCategory != null)
    {
        // Update the properties
        updateCategory.CategoryDisplayName = updateCategory.CategoryDisplayName.ToLower();
 
        // Save the changes
        WebPartCategoryInfoProvider.SetWebPartCategoryInfo(updateCategory);
 
        return true;
    }
 
    return false;
}

 

The following example gets and bulk updates web part categories.

 

private bool GetAndBulkUpdateWebPartCategories()
{
    // Prepare the parameters
    string where = "CategoryDisplayName LIKE N'My new category%'";
 
    // Get the data
    DataSet categories = WebPartCategoryInfoProvider.GetCategories(where, null);
    if (!DataHelper.DataSourceIsEmpty(categories))
    {
        // Loop through the individual items
        foreach (DataRow categoryDr in categories.Tables[0].Rows)
        {
            // Create object from DataRow
            WebPartCategoryInfo modifyCategory = new WebPartCategoryInfo(categoryDr);

 

          // Update the properties
           modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();

 
            // Save the changes
            WebPartCategoryInfoProvider.SetWebPartCategoryInfo(modifyCategory);
        }
 
        return true;
    }
 
    return false;
}

 

The following example deletes a web part category.

 

private bool DeleteWebPartCategory()
{
    // Get the web part category

  WebPartCategoryInfo deleteCategory = WebPartCategoryInfoProvider.GetWebPartCategoryInfoByCodeName("MyNewCategory");

 

    // Delete the web part category
    WebPartCategoryInfoProvider.DeleteCategoryInfo(deleteCategory);
 
    return (deleteCategory != null);
}