Tags


List of examples:

Tag groups

Creating a tag group



// Creates a new tag group object
TagGroupInfo newGroup = new TagGroupInfo();

// Sets the tag group properties
newGroup.TagGroupDisplayName = "New tag group";
newGroup.TagGroupName = "NewTagGroup";
newGroup.TagGroupDescription = "This tag group was created through the API.";
newGroup.TagGroupSiteID = SiteContext.CurrentSiteID;
newGroup.TagGroupIsAdHoc = false;

// Saves the new tag group to the database
TagGroupInfo.Provider.Set(newGroup);

> Back to list of examples

Updating a tag group



// Gets the tag group
TagGroupInfo updateGroup = TagGroupInfo.Provider.Get("NewTagGroup", SiteContext.CurrentSiteID);

if (updateGroup != null)
{
    // Updates the tag group properties
    updateGroup.TagGroupDisplayName = updateGroup.TagGroupDisplayName.ToLower();

    // Saves the updated tag group to the database
    TagGroupInfo.Provider.Set(updateGroup);
}

> Back to list of examples

Updating multiple tag groups



// Gets all tag groups defined for the current site whose name starts with 'New'
var tagGroups = TagGroupInfo.Provider.Get()
                                    .WhereEquals("TagGroupSiteID", SiteContext.CurrentSiteID)
                                    .WhereStartsWith("TagGroupName", "New");

// Loops through individual tag groups
foreach (TagGroupInfo tagGroup in tagGroups)
{
    // Updates the tag group properties
    tagGroup.TagGroupDisplayName = tagGroup.TagGroupDisplayName.ToUpper();

    // Saves the updated tag group to the database
    TagGroupInfo.Provider.Set(tagGroup);
}

> Back to list of examples

Deleting a tag group



// Gets the tag group
TagGroupInfo deleteGroup = TagGroupInfo.Provider.Get("NewTagGroup", SiteContext.CurrentSiteID);

if (deleteGroup != null)
{
    // Deletes the tag group
    TagGroupInfo.Provider.Delete(deleteGroup);
}

> Back to list of examples

Page tags

Adding tags to a page



// Gets the "/Example" page 
TreeNode page = new DocumentQuery<TreeNode>()
                    .Path("/Example", PathTypeEnum.Single)
                    .OnSite("MySite")
                    .Culture("en-us")
                    .TopN(1)
                    .FirstOrDefault();

// Gets a tag group
TagGroupInfo tagGroup = TagGroupInfo.Provider.Get("NewTagGroup", SiteContext.CurrentSiteID);

if ((page != null) && (tagGroup != null))
{
    // Assigns the tag group to the page
    page.DocumentTagGroupID = tagGroup.TagGroupID;

    // Adds the "API test" and "Examples" tags to the page
    page.DocumentTags = "\"API test\", Examples";

    // Updates the page in the database
    page.Update();
}

> Back to list of examples

Removing tags from a page



// Gets the "/Example" page
TreeNode page = new DocumentQuery<TreeNode>()
                    .Path("/Example", PathTypeEnum.Single)
                    .OnSite("MySite")
                    .Culture("en-us")
                    .TopN(1)
                    .FirstOrDefault();

if (page != null)
{
    // Checks that the page has tag content
    if (!String.IsNullOrEmpty(page.DocumentTags))
    {
        // Removes all tags from the page
        page.DocumentTags = "";

        // Updates the page in the database
        page.Update();
    }
}

> Back to list of examples