Below is a code snippet to programmatically delete a SharePoint List Item using the Server Object Model.
Note - Please replace the place holders with actual values before using the code.
Following code loops through all items in list and deletes item if Title is the same as matching Title.
using(SPSite site = new SPSite("http://SHAREPOINT_SITE_URL"))
{
using(SPWeb web = site.RootWeb)
{
SPList list = web.Lists["LIST_NAME"];
for(int i = 0; i < list.Items.Count ; i++)
{
SPListItem item = list.Items[i];
if(item["Title"] == "MATCHING_TITLE")
{
list.Items.Delete(i);
}
}
}
}
Client Object Model and REST is a more preferred and fast way for deleting SharePoint content.
Have Questions? Post them here!
More Posts related to SharePoint,
- Managed Metadata error - The data returned from the tagging UI was not formatted correctly
- How to generate client id and secret to register SharePoint App with OAuth
- Create SharePoint Site Collection with new Content database in existing web application
- Fix Error 2711 SQL RBS client - The installer has encountered an unexpected error. The specified Feature name ('Docs') not found in Feature table
- How to exclude results from SharePoint Search
- 'Edit Document' Requires a Windows Sharepoint Services-compatible application and Microsoft Internet Explorer 6.0 or higher
- [Solved] SharePoint Access Denied error editing Document Name
- Recommended size and resolution for SharePoint Online Site logo
- SharePoint Server 2016 IT Preview - new improved Features and Enhancements
- Restore deleted Office 365 SharePoint group site
- SharePoint An unexpected error has occurred - Correlation ID and PowerShell Merge-SPlogfile
- [Solved] SharePoint Search Internal server error exception
- SharePoint CAML query error - The XML source is not correct
- How to hide quick launch in SharePoint classic site
- Not receiving email notification alert in SharePoint Online workflow - Power Automate, FLOW
- Change SharePoint search results FullTextSqlQuery RowLimit 10000
- Fix Power BI error Access to the resource is forbidden when connecting SharePoint Online List as data source
- [Fix] Restricted View permission level missing in SharePoint Online site library
- How to upload file programmatically to SharePoint Document Library using Server Object Model C# .Net
- How to create classic site in SharePoint Online
- That did'nt work, Issue type User not in directory - SharePoint external access error
- Merge-SPlogfile PowerShell - SharePoint Correlation ID error
- Fix Power BI 404 not found error when connecting SharePoint Online List as Data Source
- SharePoint Server 2016 IT Preview Deprecated Removed features
- SharePoint error - An exception occurred when trying to issue security token: This implementation is not part of the Windows Platform FIPS validated cryptographic algorithms..
More Posts:
- What is Android Toast.LENGTH_SHORT and Toast. LENGTH_LONG durations - Android
- PHP Script to Upload Images to Server - PHP
- Cannot open or preview pdf with view only and restricted download access in Microsoft Teams - Teams
- Android: Unknown error code during application install : - Android
- What is Bootstrap Jumbotron and how to use it - Bootstrap
- How to configure PDF iFilter for SharePoint - SharePoint
- Microsoft Sign-in Error Code: 50058 (Request Id, Correlation Id and Timestamp) - Microsoft
- How to exclude results from SharePoint Search - SharePoint