Wednesday, 28 October 2015

Set Display Name of fields of a SharePoint List in SharePoint 2013



There may be necessity to change the display name of a field of SharePoint list in order to handle localization issue. The following code snippets illustrates how to do that in C#.





Suppose we have list called PLinks. 




    public static void SetDisplayNamePLinkListFields(ClientContext context)

        {

            Web web = context.Web;



            List lstPlinks = web.Lists.GetByTitle("PLinks");

            context.Load(lstPlinks);
            context.ExecuteQuery();


            // Get Field Reference or Internal Name

           Field fieldBackgroundImageLocation  =
           lstPlinks.Fields.GetByInternalNameOrTitle("BackgroundImageLocation");


           // Set Display Name

           fieldBackgroundImageLocation.Title ="Background Image Location" ;


           fieldBackgroundImageLocation.Update();




            Field fieldDescription = lstPlinks.Fields.GetByInternalNameOrTitle("Description");

            fieldDescription.Title ="Description of Image" ;
            fieldDescription.Update();


            Field fieldLinkLocation = lstPlinks.Fields.GetByInternalNameOrTitle("LinkLocation");

            fieldLinkLocation.Title ="Link Location";
            fieldLinkLocation.Update();


            Field fieldLaunchBehavior =
            lstPlinks.Fields.GetByInternalNameOrTitle("LaunchBehavior"); 
            fieldLaunchBehavior.Title ="Launch Behavior" ;
            fieldLaunchBehavior.Update();


            Field fieldDisplayOrder = lstPlinks.Fields.GetByInternalNameOrTitle("DisplayOrder");

            fieldDisplayOrder.Title ="Display Order" ;
            fieldDisplayOrder.Update();



            lstPlinks.Update();



        } 


Happy SharePointing....................:)

No comments:

Post a Comment