问题
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