IHold インターフェイスを実装するカスタム ソリューションの作成

最終更新日: 2010年4月15日

適用対象: SharePoint Server 2010

サイトで、"保留リストと電子情報開示" 機能をアクティブ化できます。この機能を使用すると、サイト コレクション内のコンテンツを検索し、そのコンテンツを、訴訟または監査目的で保留に追加できます。このトピックでは、IHoldsHandler インターフェイスについて説明します。カスタム保留ハンドラーはこのインターフェイスを実装してカスタム保留処理を提供できます。コンテンツを別の SharePoint Server サイトにコピーしたり、ドキュメントを所定の場所にロックしたりするのではなく、カスタム保留プロセッサは検索結果をファイル共有にエクスポートします。

リスト アイテムを保留または保留解除する場合、IHoldsHandler.OnSetHold(Microsoft.SharePoint.SPListItem,Microsoft.SharePoint.SPListItem) メソッドと IHoldsHandler.OnRemoveHold(Microsoft.SharePoint.SPListItem,System.Collections.Generic.List{Microsoft.SharePoint.SPListItem}) メソッドを IHoldsHandler インターフェイスに実装することで、カスタム処理ハンドラーを追加できます。ハンドラーは、リスト アイテムを処理した後に、該当の HoldHandlerResult オブジェクトを返すことで、既定の処理の取り消し、続行、スキップができます。

サンプルの構成、ビルド、実行を行うには

  1. コード サンプルを Microsoft Visual Studio 2010 プロジェクトにコピーし、そのファイルを CustomHold.cs として保存します。

  2. CustomHold.cs を編集して、検索結果に含まれるファイルのエクスポート先のフォルダー (コード内で \\myserver\myfolder\hold\ プレースホルダー パスで表される) を指定します。

  3. サンプルをリリース プロジェクトとしてビルドします (デバッグではない)。

  4. カスタム保留プロセッサを登録する SharePoint Server が実行されているコンピューターでフォルダーを作成します。

  5. CustomHoldProcessor\MyNewCustomHoldProcessor\bin\x64\Release フォルダーから手順 2. で指定したフォルダーに、このプロジェクトによってビルドされた内容をコピーします。

  6. registerholdprocesspr\registerholdprocesspr\bin\Release フォルダーから手順 2. で指定したフォルダーに、このプロジェクトによってビルドされた内容をコピーします。

  7. 手順 2. で作成したフォルダーに移動し、config.xml ファイルを編集して、保留プロセッサを登録するサイト コレクション、および手順 2. で指定したフォルダーの場所を指定します。

  8. MyNewCustomHoldProcesser.dll ファイルを検索し、そのファイルをグローバル アセンブリ キャッシュ (GAC) に追加します。

  9. registerholdprocesspr.exe を実行します。

以下のコード例には、IHoldsHandler インターフェイスのカスタム実装が含まれます。また、カスタム保留プロセッサを登録し、保留プロセッサの登録先サイトを指定するために必要なコードが含まれます。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Net;
using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement;
using Microsoft.Office.RecordsManagement.Holds;

//This class specifies the custom hold processor that is used to export the contents
//of a search and process job to a file share. 
namespace Microsoft.SDK.ECM.Samples.WebControls.MyNewCustomHoldProccessor
{
    public class MyHoldProccessor : IHoldsHandler
    {
        //The action to perform when setting the hold; copy the file to the specified destination. 
        public HoldHandlerResult OnSetHold(SPListItem item, SPListItem hold)
        {
            WebClient client = new WebClient();
            client.UseDefaultCredentials = true;
            string source = item.Web.Url + item.File.ServerRelativeUrl;
            //The destination to export files to.
            string destination = @"\\myserver\myfolder\hold\" +item.Name;

            client.DownloadFile(source, destination);           
            return HoldHandlerResult.Cancel;
        }

        //The action to perform when a hold is being released.
        public HoldHandlerResult OnRemoveHold(SPListItem item, List<SPListItem> holds)
        {
            foreach (SPListItem eachitem in holds)
            {
                string str = eachitem.DisplayName;                
            }
            return HoldHandlerResult.SuccessContintueProcessing;
        }
    }
}
using System;
using System.Reflection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Microsoft.SharePoint;
using Microsoft.Office.RecordsManagement;
using Microsoft.Office.RecordsManagement.Holds;

//This class registers the custom hold processor. 
namespace Microsoft.SDK.ECM.Samples.WebControls.RegisterCustomHoldProccessor
{
    class Program
    {
        static void Main(string[] args)
        {
            XmlDocument config = new XmlDocument();
            config.Load("config.xml");

            XmlElement rootEle = config.DocumentElement;
            XmlNodeList nodeList = rootEle.ChildNodes;

            string siteName = "";
            string libLocation = "";

            foreach (XmlNode eachNode in nodeList)
            {
                //This is the site collection to register the hold processor on; this is specified in config.xml.
                if (eachNode.Name == "site")
                {
                    siteName = eachNode.InnerText;
                }
                //This is the location of the files; this is specified in config.xml.
                if (eachNode.Name == "LibLocation")
                {
                    libLocation = eachNode.InnerText;
                }
            }
            Console.WriteLine("Customizing hold processor for " + siteName);
            Console.WriteLine("Search library location " + libLocation);


            SPSite site = new SPSite(siteName);
            Assembly searchengineassembly = Assembly.LoadFile(libLocation);
            Hold.RegisterCustomHoldProcessor(searchengineassembly.FullName, "MyNewCustomHoldProccessor.MyHoldProccessor", site.WebApplication);            
        }
    }
}

関連項目

概念

電子情報開示の管理

レコード管理プログラミング モデル

その他の技術情報

Walkthrough: Creating Shared Events