首先我想说我很新使用Visual Studio 2013和C#。

我想在Visual Studio 2013中制作一个用于SharePoint 2013测试环境的Web部件。 Web部件需要从不同的通知列表中获取列表项,这些公告列表可以在不同的网站上。基本上我需要能够将所有这些通知列表的内容显示为一个自定义列表。

这是场景的示例:

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"
.

所以我想在Visual Studio中制作一个自定义的Web部件,该工作室将被放置在Pubsite C上,这将从其他子区域的其他列表中显示项目。

我可以部署到我们的测试环境,我可以向页面添加自定义网页,所以我得到了那个很好的东西,但我只需要一点推动。
关于我可能需要的东西(从工具箱中可能需要)或者我如何从那些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归因
scroll top