locked
Microsoft.SharePoint.SPListItemCollection' does not contain a definition for 'toList' and no extension method 'toList' accepting a first argument of type 'Microsoft.SharePoint.SPListItemCollection' could be found RRS feed

  • Question

  • My code look like this :
    List<SPListItem> items = web.Lists["ShiftRptLibrary"].GetItems(BuildQuery(report, terminal)).ToList();

    any idea what is causing the error? thanks in advance!
    Wednesday, April 15, 2009 2:14 AM

Answers

  • As the message says: ToList(); is a method that does not exist on the object SPListItemCollection, nor is there an extention method with that name (unless you make it first)
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    Wednesday, April 15, 2009 6:18 AM
  • Make a function like this (or as an extension method if you want):

    private List<SPListItem> GetListItemsAsList(SPListItemCollection liCol) {
     List<SPListItem> toReturn = new List<SPListItem>();
     foreach(SPListItem li in liCol) {
      toReturn.Add(li);
     }
     return toReturn;
    }
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    Wednesday, April 15, 2009 10:51 AM

All replies

  • As the message says: ToList(); is a method that does not exist on the object SPListItemCollection, nor is there an extention method with that name (unless you make it first)
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    Wednesday, April 15, 2009 6:18 AM
  • Thanks for the reply, can you pls advie on how to make it? thanks
    Wednesday, April 15, 2009 9:41 AM
  • Make a function like this (or as an extension method if you want):

    private List<SPListItem> GetListItemsAsList(SPListItemCollection liCol) {
     List<SPListItem> toReturn = new List<SPListItem>();
     foreach(SPListItem li in liCol) {
      toReturn.Add(li);
     }
     return toReturn;
    }
    My blog on WSS / MOSS development is found at http://jebass.blogspot.com
    Wednesday, April 15, 2009 10:51 AM