if (site != null)
using (SPWeb web = site.OpenWeb())
SPList list = web.Lists["your list name"];
if (list != null)
foreach (SPListItem item in list.Items)
//do something here
//If you are using ascx page for webpart
//or want to display on aspx page
SPList.GetItems Method (Microsoft. SharePoint)
Returns a collection of items from the list.
Returns a collection of items from the list based on the specified query.
Returns a collection of list items from the list based on the specified view.
SPList.GetItems (SPQuery, String)
Returns a collection of list items from the list based on the specified query and view.
Because SharePoint views (SPView) don't contain definition for SPListItems or SPListItemCollections, we can programmatically retrieve list items from a list in the criteria specified by a view you've created. Items received this way also preserves sorting.
We do the trick using following code:
Complete code block:
[where "ListName" and "ViewName" are the names of your lists and views, respectively.]