Right from the API Examples documentation, should get you in the right direction:
Create a tag group
private bool CreateTagGroup()
{
// Create new tag group object
TagGroupInfo newGroup = new TagGroupInfo();
// Set the properties
newGroup.TagGroupDisplayName = "My new group";
newGroup.TagGroupName = "MyNewGroup";
newGroup.TagGroupDescription = "";
newGroup.TagGroupSiteID = SiteContext.CurrentSiteID;
newGroup.TagGroupIsAdHoc = false;
// Create the tag group
TagGroupInfoProvider.SetTagGroupInfo(newGroup);
return true;
}
Get and update a tag group
private bool GetAndUpdateTagGroup()
{
// Get the tag group
TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", SiteContext.CurrentSiteID);
if (updateGroup != null)
{
// Update the property
updateGroup.TagGroupDisplayName = updateGroup.TagGroupDisplayName.ToLower();
// Update the tag group
TagGroupInfoProvider.SetTagGroupInfo(updateGroup);
return true;
}
return false;
}
Add a tag to a document
private bool AddTagToDocument()
{
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Get the root document
TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);
// Get tag group ID
TagGroupInfo updateGroup = TagGroupInfoProvider.GetTagGroupInfo("MyNewGroup", SiteContext.CurrentSiteID);
if ((root != null) && (updateGroup != null))
{
// Add tag to document
root.DocumentTags = "\"My New Tag\"";
// Add tag to document
root.DocumentTagGroupID = updateGroup.TagGroupID;
// Update document
root.Update();
return true;
}
return false;
}
Update a document and update tags
private bool GetDocumentAndUpdateItsTags()
{
TreeProvider tree = new TreeProvider(MembershipContext.AuthenticatedUser);
// Get root document
TreeNode root = tree.SelectSingleNode(SiteContext.CurrentSiteName, "/", null, true);
if (root != null)
{
if (!String.IsNullOrEmpty(root.DocumentTags))
{
// Update the tags
root.DocumentTags = root.DocumentTags.ToUpper();
// Update document
root.Update();
return true;
}
}
return false;
}