Custom Actions Using CSOM for SharePoint Online Part 3

In the previous posts Part1 and Part 2 we have how to creat the custom actions.  In this post we will see how to delete the custom actions using CSOM.

Remove All Custom Action:

1)  Add a new button(btn_RemoveAllActions) to the web form(CustomActions.aspx)

2)Add the below code in the button click

 string Pwd = ConfigurationManager.AppSettings["Password"].ToString();
 string UserName = ConfigurationManager.AppSettings["Username"].ToString();
 string spsiteurl = ConfigurationManager.AppSettings["SPSiteUrl"].ToString();
 var secure = new SecureString();
      foreach (char c in Pwd)
       using (var clientContext = new ClientContext(spsiteurl))
             clientContext.Credentials = new SharePointOnlineCredentials(UserName, secure);
             var customlist = clientContext.Web.Lists.GetByTitle("SampleCustomList");
             UserCustomActionCollection collUCA = customlist.UserCustomActions;
             List<UserCustomAction> ualist = new List<UserCustomAction>();
              for (int i = 0; i < collUCA.Count; i++)
               foreach (var aa in ualist)
             lbl_Success.Text = "Custom  Actions Removed Successfully";

3)Now  run the web Application on click in the  btn_RemoveAllActions

4)user action will be removed from the Lists

Remove Custom Action by Title:

we can delete the custom action by Title by updating the above code slightly

  if (collUCA[i].Title == "Publish To")

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s