ソーシャル コメントを作成および取得する
最終更新日: 2010年3月15日
適用対象: SharePoint Server 2010
SocialCommentManager オブジェクトを使用すると、指定した URL に対するソーシャル コメントを作成できます。ここでは、SocialCommentManager を使用してカスタム アプリケーションでソーシャル コメントを作成および取得する方法を示します。このトピックのサンプルでは、次の参照を Microsoft Visual Studio 2010 プロジェクトに追加してあるものとします。
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
System.Web
ソーシャル コメントの作成
オーバーロードされた AddComment メソッドは、指定された単一の URL で現在のユーザーに対する単一の SocialComment オブジェクトを作成します。ソーシャル コメントは、URL と、その URL でのユーザーのコメントを表す文字列で構成されます。SocialComment は、必要に応じて、その URL で表されるオブジェクトの文字列タイトルで構成することもできます。IsHighPriority ブール値プロパティの既定の設定は false です。以下のサンプルでは、SocialCommentManager を使用して、指定した URL にソーシャル コメントを追加する方法を示します。
Uri myUri = new Uri("URL");
using (SPSite site = new SPSite("SharePoint site URL"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
mySocialCommentManager.AddComment(myUri, "comment text");
}
ソーシャル コメントの取得
オーバーロードされた GetComments メソッドは、指定された URL またはユーザーのすべての SocialComment オブジェクトを取得します。URL を指定すると、メソッドは現在の SPServerContext で現在のユーザーによってその URL に追加されたすべてのソーシャル コメントを返します。ユーザーを指定すると、メソッドは指定されたユーザーが追加したすべてのソーシャル コメントを返します。必要に応じて、取得するソーシャル コメントの最大数を指定する整数パラメーター、データベースからソーシャル コメントの取得を開始するインデックス番号を指定する 2 番目の整数パラメーター、および指定した日時より古いソーシャル コメントを除外するための DateTime パラメーターを指定することもできます。
using (SPSite site = new SPSite("SharePoint site URL"))
{
SPServiceContext context = SPServiceContext.GetContext(site);
UserProfileManager myUserProfileManager = new UserProfileManager(context);
UserProfile myUserProfile = myUserProfileManager.GetUserProfile(false);
SocialCommentManager mySocialCommentManager = new SocialCommentManager(context);
int maxItems = 10;
SocialComment[] comments = mySocialCommentManager.GetComments(myUserProfile, maxItems);
Console.WriteLine("Comments for user:");
foreach (SocialComment comment in comments)
{
Console.WriteLine(comment.Url + ": " + comment.Comment);
}
}
関連項目
参照
Microsoft.Office.Server.SocialData