Tuesday, June 26, 2012

Delete items from sharepoint list

In some case, you may want to delete item in sharepoint list. It is easy job.

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) {
            item.Delete();
        }
    }
}

No comments:

Post a Comment