Tuesday, June 14, 2011

3 ways to find SharePoint list field’s Internal name !

While working with caml query there may be cases where we may need to refer internal name of a sharepoint list and in some of the cases the display name and internal name may be different. If you try to access this list we will get object not found error.

We can find out the sharepoint field’s internal name using any of the following ways

1. Using browser (it applies to custom fields only)

Go to list settings -> Edit column. Then you can see field name from the query string

2. Object model (it applies for custom fields as well as system fields)

string siteUrl = "http://mysite";
SPSite site = new SPSite(siteUrl);
SPWeb web = site.OpenWeb();
SPList list = web.Lists["my forum"];
for (int i = 0; i < list.Fields.Count; i++)
Console.WriteLine(list.Fields[i].Title + "..." + list.Fields[i].InternalName + "...");
Console.ReadLine();

3. Powershell (it applies for custom fields as well as system fields)

[system.reflection.assembly]::loadwithpartialname("microsoft.sharepoint")
$site= New-Object Microsoft.SharePoint.SPSite ("http://mysite")
$web=$site.OpenWeb()
$list=$web.Lists["my forum"]
$list.Fields |select title, internalname| more

No comments:

Post a Comment