2

I am trying to combine two SharePoint lists into one so I can return items from two separate lists as one entity.

I have multiple Objects but I haven't found a good way to combine them no matter which ones I use.

Is there a simple way to combine the following?

SPList pubList = web.Lists["public"];
SPList secureList = web.Lists["secure"];

or

SPListItemCollection pubFiles = retrieveDocs(web, meta, pubList);
SPListItemCollection secureFiles = retrieveDocs(web, meta, secureList);

or convert these DataTables to SPListItemCollections

DataTable pubTable = pubFiles.GetDataTable();
DataTable secureTable = secureFiles.GetDataTable();

pubTable.Merge(secureTable);
2

This post answered my question.

In Summary

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"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.