by Keyvan Nayyeri via Keyvan Nayyeri on 11/27/2006 4:51:59 PM
Tags are a new feature in Community Server 2.1. Generally tags became a frequently used feature in web applications and websites in latest 2-3 years and Community Server team decided to implement them for this great up to date platform.
In previous versions of Community Server, each application type had its own mechanism to categorize its content. Categories for blog posts and subfolders of file gallery folders were two examples of these mechanisms. But in Community Server 2.1 all previous mechanisms are replaced with tags. This replacement wasn't a deep change from base because most old APIs are still valid and no change is made for them. For example, you can use old blog category APIs (I wrote about them here) in order to select, add, remove and edit tags for blog posts.
On the other hand some new APIs have been added to let you add your forum posts under some specific tags and the way that old categories had been used is replaced with a new approach to show tags in tag clouds.
Another important feature is the ability to list all tags per site, per application, per group or per section and new APIs are added to enable these capabilities. For example if you navigate to this page, can see a global tag cloud for all of my tags on my site.
Primary goal of this CS Dev Guide post is to describe new APIs to get tags for a site, a specific application, a group or a section. Mechanisms to add, remove or delete tags for specific applications are different and depend on that application type. Another topic that will be covered is to get a list of posts that match a tag or a list of tags.
CommunityServer.Components.Tag is code representation of a tag. It's very simple and has two properties to specify its name and total count of posts that are tagged under it.
CommunityServer.Components.Tags namespace has a collection of static functions with several overloads which get some parameters and return an ArrayList of Tag objects for a site, an application type, a group or a section. There are some other static methods that remove unused tags.
The purpose of these methods is obvious from their name and their parameters represent where an overload is helpful. Although there are many methods in this namespace but most of them are overloads. Therefore I list all method names and describe their purpose here:
Here there is a general point that should be mentioned: all above methods identify a group by its GroupID and a section by its SectionID. So they get their parameters as integer values for GroupID and SectionID or an array of integers for GroupIDs and SectionIDs.
Now that we discovered these theories, let's take a look at some examples.
In first example, GetPopularPostID() function returns the PostID for most popular post (post with more views in first page of results when page size is 15) in Weblog application that is tagged under .NET, C# or Community Server. In this code GetPostsMatchingTags() static method is used to get an array of tag names, an ApplicationType enumerator and two integer values for page index and page size of results.
int GetPopularPostID()
{
String[] tags = { ".NET", "C#", "Community Server" };
SearchResultSet set = Tags.GetPostsMatchingTags
(ApplicationType.Weblog, tags, 0, 15);
int mostViews = 0;
int postID = 0;
foreach (Post post in set.Posts)
if (post.Views > mostViews)
mostViews = post.Views;
postID = post.PostID;
}
return postID;
Second example, GetActiveTagName() function, uses GetTagsByGroup() static method to return a tag name with more posts for current blog group.
String GetActiveTagName()
CSContext context = CSContext.Current;
ArrayList tags = Tags.GetTagsByGroup(context.BlogGroupID);
int postCount = 0;
String mostActiveName = String.Empty;
foreach (Tag tag in tags)
if (tag.TotalCount > postCount)
postCount = tag.TotalCount;
mostActiveName = tag.Name;
return mostActiveName;
Third and last example, RemoveUnusedTagsFromThisSection() method (and a novel after this name!), uses RemoveUnsedTagsFromSection() static method to remove all unused tags for current section.
void RemoveUnusedTagsFromThisSection()
Tags.RemoveUnusedTagsFromSection(context.SectionID);
Now playing: Ricky Martin - Save The Dance
Original Post: CS Dev Guide: Tags
The content of the postings is owned by the respective author. CSharpFeeds is not responsible for the contents of the postings. This site is automatically generated and cannot be reviewed for abusive content. If you find abusive content on CSharpFeeds, please contact us. Designated trademarks and brands are the property of their respective owners. All rights reserved.