if (root != null) { // Create new web part category object WebPartCategoryInfo newCategory = newWebPartCategoryInfo(); // Set the properties newCategory.CategoryDisplayName = "My new category"; newCategory.CategoryName = "MyNewCategory"; newCategory.CategoryParentID = root.CategoryID; // Save the web part category WebPartCategoryInfoProvider.SetWebPartCategoryInfo(newCategory); returntrue; } returnfalse; }
The following example gets and updates a web part category.
privatebool 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); returntrue; } returnfalse; }
The following example gets and bulk updates web part categories.
privatebool 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 = newWebPartCategoryInfo(categoryDr);
// Update the properties modifyCategory.CategoryDisplayName = modifyCategory.CategoryDisplayName.ToUpper();
// Save the changes WebPartCategoryInfoProvider.SetWebPartCategoryInfo(modifyCategory); } returntrue; } returnfalse; }
The following example deletes a web part category.
privatebool DeleteWebPartCategory() { // Get the web part category