How to Add a User Custom Action for List Items

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.     
    4. namespace Microsoft.SDK.SharePointServices.Samples    
    5. {    
    6.     class CreateUserCustomActionList    
    7.     {    
    8.         static void Main()    
    9.         {    
    10.             string urlWebsite = "http://gauti.sharepoint.com/sites/gp";    
    11.             ClientContext clientContext = new ClientContext(urlWebsite);    
    12.             Web oWebsite = clientContext.Web;    
    13.     
    14.             List oList = oWebsite.Lists.GetByTitle("TestList");    
    15.             UserCustomActionCollection collUserCustomAction = oList.UserCustomActions;    
    16.     
    17.             UserCustomAction oUserCustomAction = collUserCustomAction.Add();    
    18.             oUserCustomAction.Location = "EditControlBlock";    
    19.             oUserCustomAction.Sequence = 100;    
    20.             oUserCustomAction.Title = "My First User Custom Action";    
    21.             oUserCustomAction.Url = urlWebsite + @"/_layouts/MyPage.aspx";    
    22.             oUserCustomAction.Update();    
    23.     
    24.             clientContext.Load(oList,    
    25.                 list => list.UserCustomActions);    
    26.     
    27.             clientContext.ExecuteQuery();    
    28.         }    
    29.     }    
    30. }    
Hit F5 and check the output.

Thanks for reading my blogs!!!
Ebook Download
View all
Learn
View all