コンテンツクエリWebPartをプログラム的に追加してSPSitedataQueryを使用する方法

sharepoint.stackexchange https://sharepoint.stackexchange.com//questions/43615

質問

現在のシナリオです。

私はxxx。という中心的なサイトがあります。

私は年間の名前と呼ばれる多くのサブサイトがあります:2012年、2011,2010など。

中央サイトでは、受益者と呼ばれるリストがあります。

全年のサイトでは、リクエストと呼ばれるリストがあります。これらのリストには、中央サイトの受益者リストにルックアップ列があります。

有益なサイトにあるすべての要求を表示するために、中央サイトに1つのWebPartを作成する必要があります。(年のサイト)。ContentQuery WebPartがSPSITESATAQUERYを使用する必要があると思うので、ContentQueryのWebPartが仕事をするのだろうか。

これは私がこれまでのコードです。

/// <summary>
        /// Update dashboard beneficieries.
        /// </summary>
        /// <param name="currentUnsafeWeb"></param>
        private void UpdateDashboardBeneficiaries(SPWeb currentUnsafeWeb)
        {
            Logger.LogDebug("NLSubsidiesSiteConfigSubsidyCentralEventReceiver", "UpdateDashboardBeneficiaries(SPWeb currentUnsafeWeb)", "BEGIN");

            SPFile page = null;
            try
            {
                page = currentUnsafeWeb.GetFile("beneficiaries.aspx");
                page.CheckOut();

                //Add Content Query WebPart or something else to show all request in all yearsubsites that are related to the beneficiaries list.


                page.CheckIn(string.Empty);

            }
            catch (Exception)
            {
                if (page != null) page.UndoCheckOut();
                throw;
            }

            Logger.LogDebug("NLSubsidiesSiteConfigSubsidyCentralEventReceiver", "ConfigureDashboardBeneficiaries(SPWeb currentWeb)", "END");
         }
.

役に立ちましたか?

解決

上述のように、SplimitedWebPartManagerを使用してプログラプティックにWebPartsを追加できます。SPSitedataQueryのサンプルコードは次のようになります。 SPSitedataQqueryクエリ= new SPSitedataQuery();

                    //Specify the fields which need to be shown.
                    query.ViewFields = "<FieldRef Name=\"Title\" />" +
                                        "<FieldRef Name=\"Type\" />" +
                                       "<FieldRef Name=\"AssignedTo\" />" +
                                       "<FieldRef Name=\"Status\" />" +
                                       "<FieldRef Name=\"DueDate\" />";

                    query.Lists = "<Lists BaseType='0'/>";
                    query.Query = "<Where><Lt><FieldRef Name='ID' /><Value Type='Counter'>0</Value></Lt></Where>";

                    // Query all Web sites in this site collection.
                    query.Webs = "<Webs Scope=\"SiteCollection\" />";
                    DataTable table = web.GetSiteData(query);
.

他のヒント

プログラムでWebPartを追加するには、 splimitedWebPartManager

例(ContentByQueryWebPartを含む)を参照してください。機能を使用しているページにWebパーツインスタンスを作成する方法 - featureceiver - splimitedWebPartManager

下記の場合も同じことをするためのサンプルコード。

ContentEditorWebPart wp = new ContentEditorWebPart();
//Add the webpart to the page
SPLimitedWebPartManager pageMgr = web.GetLimitedWebPartManager(pageURL, System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared);
pageMgr.AddWebPart(wp, "Main", 0);

//Save the page with the changes
pageMgr.SaveChanges(wp);
.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top