Cannot implicitly convert type 'Microsoft.SharePoint.SPListItemCo llection' to 'System.Collections.Generic.List<T >'_

Hi

I want use SPListItemCollection' to 'System.Collections.Generic.List<T>'.

How to achieve this.

Thanks,

Siva.

March 23rd, 2015 8:29pm

Hi Siva,

This is how I code it for looping all SPListItem in the SPListItemCollection using Generic List<T>

 public IEnumerable GetEnumerator()
        {
            using (SPSite site = new SPSite(SPContext.Current.Site.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    var list = web.Lists["Friends"];
                    var query = new SPQuery();
                    query.Query = "<FieldRef Name='ID'/>";
                    IEnumerable items = list.GetItems(query);
                    return items;
                }
            }
        }

Then calling the method would be

 var items = GetEnumerator();
            foreach(SPListItem item in items)
            {
                Response.Write(item["FirstName"]);
            }

Free Windows Admin Tool Kit Click here and download it now
March 24th, 2015 12:11am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics