Hi
I want use SPListItemCollection' to 'System.Collections.Generic.List<T>'.
How to achieve this.
Thanks,
Siva.
Technology Tips and News
Hi
I want use SPListItemCollection' to 'System.Collections.Generic.List<T>'.
How to achieve this.
Thanks,
Siva.
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"]); }