Steps
  • Open Visual Studio in your system.

  • Select Console Application template and give as name.

  • Add a Microsoft.Client Assembly reference file in right side reference tab in visual studio.

  • Replace Program.cs with the source code.
    1. using System;
    2. using Microsoft.SharePoint.Client;
    3. namespace Microsoft.SDK.SharePointServices.Samples
    4. {
    5. class CreateUserCustomActionList
    6. {
    7. static void Main()
    8. {
    9. string urlWebsite = "http://gauti.sharepoint.com/sites/gp";
    10. ClientContext clientContext = new ClientContext(urlWebsite);
    11. Web oWebsite = clientContext.Web;
    12. List oList = oWebsite.Lists.GetByTitle("TestList");
    13. UserCustomActionCollection collUserCustomAction = oList.UserCustomActions;
    14. UserCustomAction oUserCustomAction = collUserCustomAction.Add();
    15. oUserCustomAction.Location = "EditControlBlock";
    16. oUserCustomAction.Sequence = 100;
    17. oUserCustomAction.Title = "My First User Custom Action";
    18. oUserCustomAction.Url = urlWebsite + @"/_layouts/MyPage.aspx";
    19. oUserCustomAction.Update();
    20. clientContext.Load(oList,
    21. list => list.UserCustomActions);
    22. clientContext.ExecuteQuery();
    23. }
    24. }
    25. }
Hit F5 and check the output.

Thanks for reading my blogs!!!