Showing posts with label Code SP. Show all posts
Showing posts with label Code SP. Show all posts

Monday, April 17, 2017

Delete List/Library on SharePoint Online when there is no remove or delete option

There are two possible reasons as to why you cannot see the remove or delete option on a list or a library.

  1. You don't have enough permissions.
  2. 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.

Add the nugget package in below picture.



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);
            }



Now if we go back to the library and refresh the settings page of list/library. We now see that the delete link is back.


Tuesday, December 22, 2015

Detrermine which worker process to attach to while debugging SharePoint Webparts

With number of webappliations on your farm and their respective application pools, it becomes difficult to find out which worker process to attach to when you want to debug your webpart.

I assume you know how to get the name of application pool from your web application.

  • Once you do, run cmd in admin mode.
  • change directory to c:\Windows\System\Inetsrv
  • and run appcmd list wp

This will list out the worker process running for all the web applications. In my case its the following:




Then in visual studio,
  • Set breakpoints
  • deploy your solution
  • click on debug 
  • then click on attach to process and find out the process with the id which is 4316 in my case.

Thursday, November 21, 2013