Tuesday, June 26, 2012

Read item from sharepoint list

In some case, you may want to get all list item in sharepoint list. It is easy to get all those list. below are code for reading list item from sharepoint list.

Ex. You have a list named "Sample List"
using (SPSite siteCollection = new SPSite("http://server")) {
    using (SPWeb site = siteCollection.OpenWeb()) {
        SPList list = site.Lists["Sample List"];

        foreach (SPListItem item in list.Items) {
            //do what you want to do with it.
        }
    }
}
  

No comments:

Post a Comment