Delete a Sharepoint Folder using ClientContext if it is empty
To delete a Sharepoint Folder, it should be empty otherwise it will not allow us to delete it. So before deleting the folder we need to check if it is empty or not.
Below is the code in .NET (C#)
// Get the context variable of site
OfficeDevPnP.Core.AuthenticationManager authMgr = new OfficeDevPnP.Core.AuthenticationManager();
using (var ctx = authMgr.GetSharePointOnlineAuthenticatedContextTenant(_siteUrl, _userId, _password))
{
try
{
// Load the Sharepoint Documents
Web web = ctx.Web;
List list = web.Lists.GetByTitle(“Documents”);
ctx.Load(list);
ctx.ExecuteQueryRetry();
// Get the Folder using […]