ユーザー インターフェイスに操作を追加する
フィーチャーを使用すると、Windows SharePoint Services のユーザー インターフェイスのメニューに簡単に操作を追加できるようになります。この例は、フィーチャーを使用してさまざまなメニューに操作を追加する方法と展開の中でそれをアクティブにする方法を示しています。
場所とグループ ID
特定のメニューにカスタム アクションを定義するには、適切な Windows SharePoint Services 名前空間に場所を設定し、Windows SharePoint Services が特定の場所を識別するための ID を使用することでメニューを指定する必要があります。
たとえば、[サイトの設定] ページにカスタム アクションを追加するには、CustomAction 要素の Location 属性に Microsoft.SharePoint.SiteSettings を設定し、GroupId 属性を使用して、ページ内の特定の領域を指定します。
操作が異なると、ユーザー設定メニュー項目を配置するメニューを識別するために使用する [CustomAction] 属性も異なる場合があります。ただし、操作に関する他のパラメータも指定する必要があります。たとえば、バージョンによっては、操作を実行するためにユーザーのアクセス許可が必要な場合や、メニュー内の既存の操作との位置関係が必要なこともあります。以下のカスタム アクションの例に、さまざまな属性を示します。
Windows SharePoint Services のインストールで使用される既定のカスタム アクションの ID と場所の一覧については、「カスタム アクションの既定の場所および ID」を参照してください。
URL トークン
Windows SharePoint Services では、相対 URL の最初に以下のトークンを使用できます。
~site - Web サイト (SPWeb) の相対リンク。
~sitecollection - サイト コレクション (SPSite) の相対リンク。
さらに、URL 内に以下のトークンを使用できます。
{ItemId} - リスト内のアイテムを表す整数の ID。
{ItemUrl} - 作用対象のアイテムの URL。ライブラリ内のドキュメントにのみ機能します。[Beta 2 では機能しません]
{ListId} - リストを表す GUID。
{SiteUrl} - Web サイトの URL (SPWeb)。
{RecurrenceId} - 再帰インデックス。このトークンは、リスト アイテムのコンテキスト メニューでの使用がサポートされていません。
手順
サイト コレクションのユーザー インターフェイスに操作を追加するには
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES にあるセットアップ ディレクトリ内に、UserInterfaceCustomActions フォルダを作成します。
新しく作成した UserInterfaceCustomActions フォルダに Feature.xml ファイルを作成し、以下のようなフィーチャーのマニフェストを設定します。
<?xml version="1.0" encoding="utf-8" ?> <Feature Id="GUID" Title="UI Custom Actions" Description="This example shows how you can customize various areas inside Windows SharePoint Services." Version="1.0.0.0" Scope="Site" xmlns="https://schemas.microsoft.com/sharepoint/"> <ElementManifests> <ElementManifest Location="UICustomActions.xml" /> </ElementManifests> </Feature>
前の Id 属性内の GUID プレースホルダを置き換えるには、Local_Drive:\Program Files\Microsoft Visual Studio 8\Common7\Tools ディレクトリにある guidgen.exe を実行して GUID を生成します。
UICustomActions.xml ファイルを作成し、フィーチャーに含まれるさまざまな操作に関連する要素を定義します。以下の例に示すように、各操作の URL で .aspx ファイルを示し、そこに要求の発行元を識別する値を渡します。
<?xml version="1.0" encoding="utf-8" ?> <Elements xmlns="https://schemas.microsoft.com/sharepoint/"> <!-- Document Library Toolbar New Menu Dropdown --> <CustomAction Id="UserInterfaceCustomActions.DocLibNewToolbar" RegistrationType="List" RegistrationId="101" GroupId="NewMenu" Rights="ManagePermissions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="MY DOCLIB NEW MENU TOOLBAR BUTTON"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?NewMenu"/> </CustomAction> <!-- Document Library Toolbar Upload Menu Dropdown --> <CustomAction Id="UserInterfaceCustomActions.DocLibUploadToolbar" RegistrationType="List" RegistrationId="101" GroupId="UploadMenu" Rights="ManagePermissions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="MY DOCLIB UPLOAD MENU TOOLBAR BUTTON"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?UploadMenu"/> </CustomAction> <!-- Document Library Toolbar Actions Menu Dropdown --> <CustomAction Id="UserInterfaceCustomActions.DocLibActionsToolbar" RegistrationType="List" RegistrationId="101" GroupId="ActionsMenu" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="MY DOCLIB ACTIONS MENU TOOLBAR BUTTON"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?ActionsMenu"/> </CustomAction> <!-- Document Library Toolbar Settings Menu Dropdown --> <CustomAction Id="UserInterfaceCustomActions.DocLibSettingsToolbar" RegistrationType="List" RegistrationId="101" GroupId="SettingsMenu" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="MY DOCLIB SETTINGS MENU TOOLBAR BUTTON"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?SettingsMenu"/> </CustomAction> <!-- Site Actions Dropdown --> <CustomAction Id="UserInterfaceCustomActions.SiteActionsToolbar" GroupId="SiteActions" Location="Microsoft.SharePoint.StandardMenu" Sequence="1000" Title="MY SITE ACTIONS BUTTON"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?SiteActions"/> </CustomAction> <!-- Per Item Dropdown (ECB)--> <CustomAction Id="UserInterfaceCustomActions.ECBItemToolbar" RegistrationType="List" RegistrationId="101" Type="ECBItem" Location="EditControlBlock" Sequence="106" Title="MY ECB ITEM"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?ECBItem"/> </CustomAction> <!-- Display Form Toolbar --> <CustomAction Id="UserInterfaceCustomActions.DisplayFormToolbar" RegistrationType="List" RegistrationId="101" Location="DisplayFormToolbar" Sequence="106" Title="MY DISPLAY FORM TOOLBAR"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?DisplayFormToolbar"/> </CustomAction> <!-- Edit Form Toolbar --> <CustomAction Id="UserInterfaceCustomActions.EditFormToolbar" RegistrationType="List" RegistrationId="101" Location="EditFormToolbar" Sequence="106" Title="MY EDIT FORM TOOLBAR"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?EditFormToolbar"/> </CustomAction> <!-- Site Settings --> <CustomAction Id="UserInterfaceCustomActions.SiteSettings" GroupId="Customization" Location="Microsoft.SharePoint.SiteSettings" Sequence="106" Title="MY SITE SETTINGS LINK"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?Customization"/> </CustomAction> <!-- Content Type Settings --> <CustomAction Id="UserInterfaceCustomActions.ContentTypeSettings" GroupId="General" Location="Microsoft.SharePoint.ContentTypeSettings" Sequence="106" Title="MY CONTENT TYPE SETTINGS LINK"> <UrlAction Url="/_layouts/CustomActionsHello.aspx?General"/> </CustomAction> </Elements>
使用できるその他の共通の GroupId 値には、ViewToolbar、ViewSelectorMenu、および PersonalActions ([ようこそ] メニュー) が含まれます。
以下のような CustomActionsHello.aspx ファイルを \TEMPLATE\LAYOUTS ディレクトリに追加し、前の手順で作成したリンクのターゲットとして使用します。
<%@ Page Language="C#" Inherits="System.Web.UI.Page"%> <% string clientQuery = Page.ClientQueryString; if (clientQuery == "NewMenu") { Response.Write("You came from the new document menu."); } else if (clientQuery == "UploadMenu") { Response.Write("You came from the upload menu."); } else if (clientQuery == "ActionsMenu") { Response.Write("You came from the actions menu."); } else if (clientQuery == "SettingsMenu") { Response.Write("You came from the settings menu."); } else if (clientQuery == "SiteActions") { Response.Write("You came from the Site Actions menu."); } else if (clientQuery == "ECBItem") { Response.Write("You came from the document's context menu."); } else if (clientQuery == "DisplayFormToolbar") { Response.Write("You came from the display item properties form."); } else if (clientQuery == "EditFormToolbar") { Response.Write("You came from the edit item properties form."); } else if (clientQuery == "Customization") { Response.Write("You came from the Site Settings menu."); } else if (clientQuery.StartsWith("General")) { Response.Write("You came from the Content Type Settings menu."); } %>
コマンド プロンプトで、以下のコマンドを入力して、展開に Feature をインストールし、指定したサブサイトで Feature をアクティブにしてから、Microsoft Internet Information Services (IIS) をリセットして、変更を有効にします。
a. stsadm -o installfeature -filename UserInterfaceCustomActions\feature.xml b. stsadm -o activatefeature -filename UserInterfaceCustomActions\feature.xml -url https://Server/Site/Subsite c. iisreset
追加したカスタム アクションを参照するには、サイト コレクションの Web サイトのホーム ページから、以下の場所に移動します。
[サイトの操作] をクリックし、[サイトの操作] メニューの新しい操作を参照します。
[サイトの操作] メニューで [サイトの設定] をクリックし、[サイトの設定] ページの [外観] セクションの新しい操作を参照します。
ドキュメント ライブラリに移動し、ツール バーの各メニューを開いて、各メニューの新しい操作を参照します。
アイテムが含まれるドキュメント ライブラリで、アイテムに対応する下矢印をクリックし、制御ブロックの編集メニューの新しい操作を参照します。
アイテムに関連する制御ブロックの編集メニューで、[プロパティの表示] と [プロパティの編集] をクリックし、[表示フォーム] と [編集フォーム] ツール バーの新しい操作を参照します。