add multiple SPList to SPListItemCollection

空扰寡人 提交于 2020-01-02 20:10:05

问题


I have 1 SPList to 1 SPListItemCollection , I want to add two SPList to 1 SPListItemCollection

1

SPList list = SPContext.Current.Web.Lists[Constants.ListNames.Name];
SPListItemCollection allItems = list.GetItems(spQuery);

2

SPList list = SPContext.Current.Web.Lists[Constants.ListNames.Name];
SPList list2 = SPContext.Current.Web.Lists[Constants.ListNames.Name2];
    SPListItemCollection allItems = list.GetItems(spQuery);
allItems??? 

回答1:


I always like to use List<> to handle these. To do that, make sure you add

using System.Linq;

Then

List<SPListItem> allItems = new List<SPListItem>();
allItems.AddRange(list.GetItems(spQuery).Cast<SPListItem>().ToList());
allItems.AddRange(list2.GetItems(spQuery).Cast<SPListItem>().ToList());

//Do something to the "allItems"

That's it



来源:https://stackoverflow.com/questions/34099035/add-multiple-splist-to-splistitemcollection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!