Thursday, April 11, 2013

How to Reliable SharePoint Line Programmatically


Here is how we can Reliable SharePoint Record or Website Field/Column Programmatically with PowerShell and C# Item Design code:




PowerShell Code to  Rename a SharePoint Field:
?
1
2
3
4
5
6
7
8
9
10
11
12
13
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
 
#Get the "Risk Metrics" List
$list= $web.Lists.TryGetList("Risk Metrics")
 
#Get "Project Name" Field
$field = $list.fields | where {$_.Title -eq "Project Name"}
 
#Set Field Display Name and Update
$field.Title ="Program Name"
$field.Update()

Rename a SharePoint Field Programmatically (C#):

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using(SPSite site=new SPSite("http://sharepoint.crescent.com"))
 {
     //Get the "Risk Metrics" List
     SPList list = site.RootWeb.Lists["Risk Metrics"];
 
     //Get "Project Name" Field
     SPField field = list.Fields["Project Name"];
 
     //Set Field Display Name and Update
     field.Title = "Program Name";
     field.Update();
 
     //You can also use: list.Fields["Project Name"].Title = "Project Name";
    //list.Update();                
 }



No comments:

Post a Comment