Custom Actions Using CSOM For SharePoint Online

In this Series of posts  you will come to know about below two custom actions.

  • Ribbon custom action
  • Menu Item custom action

We have so many types of Custom Actions are there in SharePoint 2013

  1. Menu Custom Action
  2. Page Custom Action
  3. Central Administration Custom Action
  4. Server Ribbon Custom Action

In this  Series of posts we post we will see how to add  and Remove  Menu(ECB) and Ribbon  custom actions to different types of lists (Custom List, Document Library  and Calendar)  in  SharePoint online  using CSOM (.net managed) code.

Menu Custom Actions(ECB ) :

1) Take a empty web application and Add the  Microsoft.SharePointOnline.CSOM nuget package to your  solution using nuget Package Manager.

2)Add a web form (CustomActions.aspx) to the empty project.

3)Create a custom list in SharePoint online  Site Collection say(SampleCustomList) and add some sample items in that.


4) Add the SharePoint online Site Collection URL,username and password in the web.config as below


5) Add a  asp button(btn_clEcbCustomActions) in  aspx form and also add the below code in the  click event

                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");
                    Microsoft.SharePoint.Client.UserCustomActionCollection collUserCustomAction = customlist.UserCustomActions;
                    UserCustomAction newcustomaAction = collUserCustomAction.Add();
                    newcustomaAction.Location = "EditControlBlock";
                    newcustomaAction.Sequence = 100;
                    newcustomaAction.Title = "Custom List ECB Menu";
                    newcustomaAction.Url = "javascript:alert('Custom List ECB custom Action')";                  

                    lbl_Success.Text = "Custom List ECB Menu Created Successfully";
            catch (Exception ex)

                lbl_Error.Text = ex.Message.ToString();

Note: please refer the MSDN link for more details on Custom Action  Custom Action Locations and IDs

6)Now run that web application and Click on the  btn_clEcbCustomActions button.


7) Custom action is created  successfully for the list  in ECB menu


8) When you click on the custom action we will get an alert as defined in the newcustomaAction.Url property


9) For demo  i had given the alert message  for the URL property.

 newcustomaAction.Url = "javascript:alert('Custom List ECB custom Action')";

if we  want to open a page in the popup, update the url property as below

newcustomaAction.Url = "javascript:OpenPopUpPageWithTitle('', RefreshOnDialogClose, 600, 400,'SampleCustomList')";

10) Now the popup will come  with the  specified URL as below


Like this we can create ECB Menu custom actions for all type of lists in SharePoint online

In the Next article we  will see how to create Ribbon action for lists in SharePoint Online

3 thoughts on “Custom Actions Using CSOM For SharePoint Online

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