新しいアクティビティ タイプを作成する
最終更新日: 2010年3月30日
適用対象: SharePoint Server 2010
Microsoft SharePoint Server 2010 を使用すると、イベントを作成してユーザーのニュースフィードに挿入するために使用できる新しいアクティビティ タイプを作成することで、個人用サイト ホストの [個人用ニュースフィード] ページを拡張できます。以下の方法例では、新しい ActivityType オブジェクトを作成し、それを ActivityTemplate オブジェクトと関連付けてから、(その ActivityTemplate を使用して) ニュースフィードでのイベントの表示方法が定義されているリソース ファイルと関連付ける方法を示します。このトピックに含まれるタスクを実行する方法を示すコード例については、「コード サンプル: マルチキャスト アクティビティ イベント コンソール アプリケーション」と「コード サンプル: 仕事仲間アクティビティ イベントへのリンクを送る」を参照してください。このトピックでは、リソース (.resx) ファイルを作成して \Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\Resources ディレクトリに展開してあり、次の参照を Microsoft Visual Studio 2010 プロジェクトに追加してあるものとします。
Microsoft.SharePoint
Microsoft.Office.Server
Microsoft.Office.Server.UserProfiles
System.Web
新しいアクティビティ タイプの作成
各 ActivityType オブジェクトには ActivityTemplates プロパティが含まれます。このプロパティには、ActivityTemplate オブジェクトのコレクションが格納されています。ActivityTemplate クラスに含まれるプロパティは、アクティビティ フィードのアクティビティ イベントを作成および収集するために構築するカスタム アプリケーションと共に作成しいて展開する必要のある (リソース ファイルで定義される) 表示テンプレートにクラスを接続します。リソース ファイルを作成する方法については、「リソース ファイルの作成 (英語)」を参照してください。特定の ActivityType は 1 回だけ作成するので、ソリューションで重複して作成しないように注意する必要があります。次の方法サンプルでは、新しい ActivityType オブジェクトを作成してその表示を定義する方法を示します。
private void SetupCustomActivity(SPSite site)
{
string resFile = "name of your resource (.resx) file";
//Get an SPServiceContext from the site.
SPServiceContext context = SPServiceContext.GetContext(site);
//Create a UserProfileManager.
UserProfileManager upm = new UserProfileManager(context);
//Get the current user's profile.
UserProfile p = upm.GetUserProfile(true);
//Create an activity manager.
ActivityManager am = new ActivityManager(p, context);
//Make sure that the current user has permission to do this
bool hasrights = am.PrepareToAllowSchemaChanges();
// Create an activity application.
ActivityApplication app = am.ActivityApplications["Name of Activity Application"];
if (app == null)
{
app = am.ActivityApplications.Create("Name of Activity Application");
app.Commit();
}
//Create an ActivityType; check to see whether it already exists.
ActivityType activityType = app.ActivityTypes["Name of Activity Type"];
if (activityType == null)
{
activityType = app.ActivityTypes.Create("Name of Activity Type");
//Associate the ActivityType with the resource file that you have deployed and with the
//localized string name stored in the resource file.
activityType.ActivityTypeNameLocStringResourceFile = resFile;
activityType.ActivityTypeNameLocStringName = "Activity Type Localized String Name";
activityType.IsPublished = true;
activityType.IsConsolidated = true;
activityType.Commit();
}
//Create a single value ActivityTemplate; check to see whether it already exists.
ActivityTemplate urlTemplateSV = activityType.ActivityTemplates[ActivityTemplatesCollection.CreateKey(false)];
if (urlTemplateSV == null)
{
urlTemplateSV = activityType.ActivityTemplates.Create(false);
//Associate the template with the resource file that you have deployed and with the
//localized string name stored in the resource file.
urlTemplateSV.TitleFormatLocStringResourceFile = resFile;
urlTemplateSV.TitleFormatLocStringName = "Activity Template Localized String Name ";
urlTemplateSV.Commit();
}
}
関連項目
参照
Microsoft.Office.Server.ActivityFeed
概念
[方法] ユーザーのニュースフィードにイベントを作成して挿入する
その他の技術情報
Microsoft SharePoint Server 2010: Activity Feeds Console Application (英語)