将多个SPList添加到SPListItemCollection

时间:2015-12-04 23:10:55

标签: sharepoint sharepoint-2013 sharepoint-list

我有1个SPList到1个SPListItemCollection,我想将两个SPList添加到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 个答案:

答案 0 :(得分:2)

我总是喜欢使用List<>处理这些。为此,请确保添加

using System.Linq;

然后

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"

那是