Querying SharePoint Lists

Ok, this one is fairly basic... I'm just putting it here because I use this bit of code really, really often.

SPWeb mySite = SPContext.Current.Web;
SPListItemCollection listItems = mySite.Lists["NameOfList"].Items;

int countResults = 0;

for (int i = 0; i < listItems.Count; i++)
{
    SPListItem item = listItems[i];
    writer.Write(item["Title"].ToString()+"<br />");
}

Nice and simple...

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.