通过代码获取sharepoint2010的“我喜欢(I like it)”、“标签(Tags and Notes)”、“记事本”以及“文档等级”活动内容
最近有个项目要实现:sharepoint2010的“我喜欢(I like it)”、“标签(Tags and Nots)”、“记事本”以及“文档等级”活动内容如何通过代码获取?
通过MSDN资料我们知道是通过User Profiles获取的。
http://msdn.microsoft.com/en-us/library/microsoft.office.server.socialdata
看看UserProfile的结构图:
标签:我喜欢
打开一个文档库或列表,点击【我喜欢】,如下图:
点击后会产生一个标签活动,去个人站点下查看会看到如下图内容:
自定义标签
点击后会产生一个标签活动,去个人站点下查看会看到如下图内容:
记事本内容
去个人站点下查看会看到如下图内容:
文档等级活动
创建一个文档库,启用等级设置。如下图:
接着上传一个文档,打等级标记
代码部分:
得到标签的活动内容
//*****************************************************得到标签的活动内容
string currentSite = "http://win-moss:8010/"; ;
using (SPSite aSite = new SPSite(currentSite))
{
SPServiceContext currentContext = SPServiceContext.GetContext(aSite);
//Get the UserProfileManager from SPServiceContext.
UserProfileManager userProfMan = new UserProfileManager(currentContext);
//Get the current user.
string userName = Environment.UserDomainName + "\\" + Environment.UserName;
UserProfile currentUser = userProfMan.GetUserProfile(userName);
SocialTagManager mySocialTagManager = new SocialTagManager(currentContext);
//string[] colleagueAccountNames = new string[currentUser.Colleagues.GetItems().GetLength(0)];
SocialTag[] mySocialTags = mySocialTagManager.GetTags(currentUser);
string temp = string.Empty;
foreach (SocialTag item in mySocialTags)
{
temp += "||活动:" + item.Title + "||" + item.LastModifiedTime;
}
Console.WriteLine(temp);
temp = "";
SocialTerm[] myTerms = mySocialTagManager.GetTerms(currentUser);
foreach (SocialTerm item in myTerms)
{
temp += ">>标签:" + item.Term.Name;
}
Console.WriteLine(temp);
Console.Read();
}
得到记事本的活动内容
//*********************************************************得到记事本的活动内容
string currentSite = "http://win-moss:8010/"; ;
using (SPSite aSite = new SPSite(currentSite))
{
SPServiceContext currentContext = SPServiceContext.GetContext(aSite);
//Get the UserProfileManager from SPServiceContext.
UserProfileManager userProfMan = new UserProfileManager(currentContext);
//Get the current user.
string userName = Environment.UserDomainName + "\\" + Environment.UserName;
UserProfile currentUser = userProfMan.GetUserProfile(userName);
SocialCommentManager socialCommentManager = new SocialCommentManager(currentContext);
SocialComment[] allComments = socialCommentManager.GetComments(currentUser);
string temp = string.Empty;
foreach (SocialComment item in allComments)
{
temp += "||" + item.Title + item.Comment;
}
Console.WriteLine(temp);
Console.Read();
}
得到文档评星级的活动内容
////*********************************************************得到文档评星级的活动内容
string currentSite = "http://win-moss:8010/"; ;
using (SPSite aSite = new SPSite(currentSite))
{
SPServiceContext currentContext = SPServiceContext.GetContext(aSite);
//Get the UserProfileManager from SPServiceContext.
UserProfileManager userProfMan = new UserProfileManager(currentContext);
//Get the current user.
string userName = Environment.UserDomainName + "\\" + Environment.UserName;
UserProfile currentUser = userProfMan.GetUserProfile(userName);
SocialRatingManager socialRatingManager = new SocialRatingManager(currentContext);
SocialRating[] allRatings = socialRatingManager.GetRatings(currentUser);
string temp = string.Empty;
foreach (SocialRating item in allRatings)
{
temp += "||" + item.Title +">>" + item.Rating;
}
Console.WriteLine(temp);
Console.Read();
}