Different ways to delete all items from SharePoint list

This SharePoint tutorial, we will discuss how to delete all items from a SharePoint list using out of box feature as well as by using the SharePoint server object model. We will also see, how to delete all items from SharePoint list using PowerShell.

There might have some situation where you want to delete all items from a larger list which may have more than thousands of items.

Delete all items from a SharePoint list programmatically using the server object model

This example, we will discuss how to delete all items from a SharePoint list programmatically using the server object model.

protected void Page_Load(object sender, EventArgs e)
{
SPSite site = new SPSite("http://SiteURL");
SPWeb web = site.OpenWeb();
web.AllowUnsafeUpdates = true;
SPList list = web.Lists[List Name];

DeleteAllRerecords(list);
web.Update();
}

void DeleteAllRerecords(SPList list)
{
SPListItemCollection items = list.Items;
for (int i = items.Count – 1; i >= 0; i–)
{
items[i].Delete();
}
}

Delete Items from SharePoint List using Out of box feature (for browsers other than IE like Chrome)

If you the open the list to delete all the items then you have to select all the items individually to delete. But if your list has more than thousands of items then it will be difficult to do this process. But you can do in the simplest approach.

Open the site and then click on the settings icon and then click on Site Settings. Then in the Site Settings page click on the “Content and structure” link under Site Administration section like below:

Delete all items from SharePoint list

Then from the Site Content and Structure page, Select the particular list whose items you wants to delete like below:

Delete all items from SharePoint online list using powershell

Then from the right-hand side click on the icons (shown in the yellow color) to select all the items and then click on the Delete option from the Actions button like below:

Delete all items from SharePoint list using powershell

This way you can delete all the items from the list.

For IE Browser:
If you are using IE browser, then first open the list view settings and then go to the Tabular View section in the down and select the checkbox “Allow individual item checkboxes “.

Delete all items from SharePoint 2016 list

Now you open the list and select the tick box (selected in yellow color) to select all the item like below:

Delete all items from SharePoint 2013 list

Delete Items from a SharePoint List using PowerShell

Now, we will discuss how to delete all list items using PowerShell in SharePoint 2013. The same PowerShell script we can use to delete all list items in SharePoint 2016.

We can write PowerShell script in Windows PowerShell ISE or you can use Visual studio code to write, debug and test PowerShell scripts.

Below is the PowerShell script. Open SharePoint Management Shell and run below PowerShell command.

I have a list name as “MyTestList99” which has below items. I want to delete all items using PowerShell.

Delete all items from SharePoint list programmatically
$web = Get-SPweb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/"
$list = $web.Lists["MyTestList99"]
$items = $list.items
foreach ($item in $items)
{
$deleteitem=$list.GetItemById($item.ID)
$deleteitem.Delete()
}

After running above command, if you will refresh the SharePoint list, you will not get any item in it.

Delete all items from SharePoint list

This is how we can delete all SharePoint list items using PowerShell. The same code will work for SharePoint 2013/2016.

Delete all list items in SharePoint Online using PowerShell

Now, we will see, how to delete list items in SharePoint Online Office 365 using the Client Side Object Model (CSOM) with PowerShell. If you have more items to delete from SharePoint List, we can go for batch delete.

I would like to highlight programmatically when we delete list items, those are not moved to the Recycle Bin for the SharePoint site.

Please find the below code which will delete all items from the SharePoint list, the PowerShell script is hared by Sambita.

cls
Add-Type -Path "E:\PSDLL\Microsoft.SharePoint.Client.dll"
Add-Type -Path "E:\ PSDLL\Microsoft.SharePoint.Client.Runtime.dll"
$0 = $MyInvocation.MyCommand.Definition
$dp0 = [System.IO.Path]::GetDirectoryName($0)
$url = "https://onlysharepoint2013.sharepoint.com/sites/test123/"
$username = "sambitha@microsofttest.com"
$password = "*****"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
#connect/authenticate to sharepoint online and get ClientContext object…
$clientContext = New-Object Microsoft.SharePoint.Client.ClientContext($url)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($username, $securePassword)
$clientContext.Credentials = $credentials
if(!$clientContext.ServerObjectIsNull.Value)
{
$web = $clientContext.Site.RootWeb
$clientContext.Load($web)
$clientContext.ExecuteQuery()
$list=$clientContext.Web.Lists.GetByTitle(‘TestList’)
$clientContext.Load($list)
$clientContext.ExecuteQuery()
$query = New-Object Microsoft.SharePoint.Client.CamlQuery
$query.ViewXml="<View><RowLimit>1000</RowLimit></View>"
$items=$list.GetItems($query)
$clientContext.Load($items)
$clientContext.ExecuteQuery()

if ($items.Count -gt 0)
{
for ($i = $items.Count-1; $i -ge 0; $i–)
{
$items[$i].DeleteObject()
}
$clientContext.ExecuteQuery()
}
}

This is how we can delete all items from a SharePoint Online list using PowerShell.

You may like following SharePoint tutorials:

This SharePoint tutorial we learned, how to delete all item from a SharePoint list using the SharePoint server object model. Also, we saw how to delete all items from a SharePoint list using PowerShell and browser.

Donwload Hub site pdf

Download SharePoint Online Tutorial PDF FREE!

Get update on Webinars, video tutorials, training courses etc.

>