There are two possible reasons as to why you cannot see the remove or delete option on a list or a library.
- You don't have enough permissions.
- The library or list was created with "Allow Deleting" property set to false.
In this post I am going to talk more about Point #2 and discuss how can we set it to true using CSOM for SharePoint Online.
I am creating a console application using visual studio and using the latest version of SharePoint online CSOM. The older version of this nugget package does not contain enabling "Allow Deletion: . So make sure you get the latest version.
string siteCollectionUrl = "https://company.sharepoint.com/"; string userName = "user@microsoft.com"; string password = "xxxxxxxx"; ClientContext ctx = new ClientContext(siteCollectionUrl); SecureString secureString = new SecureString(); password.ToList().ForEach(secureString.AppendChar); ctx.Credentials = new SharePointOnlineCredentials(userName, secureString); Web web = ctx.Web; ctx.Load(web); ctx.ExecuteQuery(); Console.WriteLine(web.Url.ToString()); Console.WriteLine("Current Site: " + web.Title); List library = web.Lists.GetByTitle("Documents"); ctx.Load(library, l=>l.AllowDeletion); ctx.ExecuteQuery(); Console.WriteLine("Allow deletion for library is : " + library.AllowDeletion);
Since "Allow deletion" property is set to false. We have to set it to true to get back the delete list/library link.
if (!library.AllowDeletion) { library.AllowDeletion = true; library.Update(); ctx.ExecuteQuery(); ctx.Load(library, l => l.AllowDeletion); ctx.ExecuteQuery(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Allow deletion for library after update is : " + library.AllowDeletion); }
0 comments:
Post a Comment