Visual StudioでカスタムWebパーツを作成しながら、異なるサイト間のリストからデータを収集する方法

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

質問

まず最初に私は私がVisual Studio 2013とC#でも働くことが非常に新しいです。

SharePoint 2013テスト環境のVisual Studio 2013で特定のWebパートを作成したいです。 Webパーツは、さまざまなアナウンスリストからリストアイテムを取得する必要があるため、これらのアナウンスリストは異なるサイトにあります。基本的には、それらのアナウンスリストリストの内容を1つのカスタムリストに表示できる必要があります。

これはシナリオの例です:

Subsite A: has a list named "List X"
Subsite B: has a list named "List Y"
Subsite C: has a custom web part that shows items from "List X" and "List Y"
.

だから私はセーブサイトCに置かれることになるVisual StudioでカスタムWebパーツを作成したい。

私たちのテスト環境に展開することができ、私はそのページにカスタムWebパーツを追加することができ、私はそれがいいですが、私はちょっとしたプッシュが必要です。
私が(ツールボックスから)必要とするかもしれないもの(ツールボックスから)または私がそれらのSharePointリストからデータを取得する方法についてのいくつかの提案(提案、リンク、何でも)、それはすべて大歓迎です。

あなたの助けと時間は大いに感謝されています!

役に立ちましたか?

解決

You can use SPSiteDataQuery for getting List data from multiple sub sites of same site collection.

Below is the basic code to start with ,bywhich you can use to get all announcement list items from the different sub sites:

using (SPSite oSPsite = new SPSite(SPContext.Current.Web.Url))
        {
            using (SPWeb oSPWeb = oSPsite.OpenWeb())
            {
                // Fetch using SPSiteDataQuery
                SPSiteDataQuery query = new SPSiteDataQuery();
                query.Lists = "<Lists ServerTemplate=\"104\" />";//104=List template ID for "Anouncements"
                query.ViewFields = "<FieldRef Name=\"Title\" />";//Add other fields which you want to get.
                query.Query = "";//you can add your caml query if you want to filter the list items returned
                query.Webs = "<Webs Scope=\"SiteCollection\" />";//Scope is set to site collection to get data from all anouncement lists in that site collection.
                DataTable dataTable = oSPWeb.GetSiteData(query);
            }
        }
ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top