次の方法で共有


手順 1: ASP.NET Web パーツ アセンブリを開発する

単純なフィルタ コンシューマ Web パーツを作成するには、ASP.NET Web パーツ アセンブリの開発から始めます。通常は、System.Web.UI.WebControls.WebParts.WebPart 基本クラスから派生させたクラスでクラス ライブラリを作成することにより作成できます。

ASP.NET アセンブリの開発の詳細については、次の ASP.NET 2.0 ドキュメントを参照してください。

  • ASP.NET Web Parts Quick Start

  • ASP.NET Web Parts Documentation

  • ASP.NET 2.0 Web Part Connections

前提条件

このトピックでは、ユーザーが Microsoft Visual Studio 2005 を使用していることを前提としています。

ASP.NET Web パーツ アセンブリを作成するには

  1. Visual Studio 2005 を起動します。

  2. 新しい C# クラス ライブラリ プロジェクトを開始します。

  3. System.Web、Microsoft.Office.Server、Microsoft.SharePoint、および Microsoft.SharePoint.Portal への参照を追加します。

  4. .cs ファイルに、次のコードをコピーして貼り付けます。

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Text;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using aspnetwebparts = System.Web.UI.WebControls.WebParts;
    using Microsoft.Office.Server.Utilities;
    using wsswebparts = Microsoft.SharePoint.WebPartPages;
    using Microsoft.SharePoint.Portal.WebControls;
    using System.Collections.ObjectModel;
    using Microsoft.SharePoint.Utilities;
    using System.Data;
    using System.Collections;
    
    namespace MyWebPartLibrary
    {
        public class SimpleFilterConsumerWebPart : aspnetwebparts.WebPart
        {
    
            List<wsswebparts.IFilterValues> providers = new List<wsswebparts.IFilterValues>();
    
    
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
            }
    
    
            [aspnetwebparts.ConnectionConsumer("Simple Consumer", "IFilterValues", AllowsMultipleConnections = false)]
            public void SetConnectionInterface(wsswebparts.IFilterValues provider)
            {
                this.providers.Add(provider);
                if (provider != null)
                {
                    List<wsswebparts.ConsumerParameter> l = new List<wsswebparts.ConsumerParameter>();
                    l.Add(new wsswebparts.ConsumerParameter("Value", wsswebparts.ConsumerParameterCapabilities.SupportsMultipleValues | wsswebparts.ConsumerParameterCapabilities.SupportsAllValue));
                    provider.SetConsumerParameters(new ReadOnlyCollection<wsswebparts.ConsumerParameter>(l));
                }
            }
    
            protected override void RenderContents(HtmlTextWriter output)
            {
                this.EnsureChildControls();
                foreach (wsswebparts.IFilterValues provider in this.providers)
                {
                    if (provider != null)
                    {
                        string prop = provider.ParameterName;
                        ReadOnlyCollection<String> values = provider.ParameterValues;
    
                        if (prop != null && values != null)
                        {
                            output.Write("<div>" + SPEncode.HtmlEncode(prop) + ":</div>");
                            foreach (string v in values)
                            {
                                if (v == null)
                                {
                                    output.Write("<div>&nbsp;&nbsp;<i>&quot;(empty)&quot;/null</i></div>");
                                }
                                else if (v.Length == 0)
                                {
                                    output.Write("<div>&nbsp;&nbsp;<i>empty string</i></div>");
                                }
                                else
                                {
                                    output.Write("<div>&nbsp;&nbsp;" +v + "</div>");
                                }
                            }
                        }
                        else
                        {
                            output.Write("<div>No filter specified (all).</div>");
                        }
                    }
                    else
                    {
                        output.Write("<div>Not connected.</div>");
                    }
    
                    output.Write("<hr>");
                }
            }
    
        }
    }
    
  5. ソリューションをコンパイルします。これで、単純なフィルタ コンシューマ Web パーツを含むアセンブリができました。

Next Steps

手順 2: Bin またはグローバル アセンブリ キャッシュへのアセンブリの配置