Use the following code
SPSite site = null;
SPWeb web = null;
try
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
site = SPContext.Current.Site;
site.AllowUnsafeUpdates = true;
web = site.OpenWeb();
SPList list = web.Lists["Test"];
SPQuery oQuery = new SPQuery();
oQuery.Query = "
SPListItemCollection oDeleteCollection = list.GetItems(oQuery);
if (oDeleteCollection.Count > 0)
{
for (int i = oDeleteCollection.Count - 1; i > -1; i--)
{
oDeleteCollection.Delete(i);
}
}
});
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
No comments:
Post a Comment