Hi,
I am trying to pass the listitemcollection to a generic list. But I am getting error as Object reference not set.
I have used the below code:
using (SPSite oSite = new SPSite(SPContext.Current.Site.Url))
{
using (SPWeb oWeb = oSite.RootWeb)
{
SPList lstTestLibrary = oWeb.Lists["TESTLibrary"];
SPQuery sQuery = new SPQuery();
sQuery.Query = "<Where><IsNotNull><FieldRef Name='ID' /></IsNotNull></Where>";
sQuery.ViewFields = string.Concat(
"<FieldRef Name='Title' />","<FieldRef Name='ID' />","<FieldRef Name='FileLeafRef' />","<FieldRef Name='FileDirRef' />");
sQuery.ViewFieldsOnly = true;
//This commented line works
// SPListItemCollection myColl = lstTestLibrary.GetItems(sQuery);
//Getting error in the below line:
List<SPListItem> listItems = lstTestLibrary.GetItems(sQuery).Cast<SPListItem>().ToList();
}
}Is it possible to set the data to a Generic list? How to fix this?
Thanks