When you develop ASP.net applications that interact with SharePoint lists, you may come to a point that you need to retrieve value from each column of a list by referencing the name of the list coluumn, however, you may end up with an error saying the column does no exist. This is because the name you use to create a column in SharePoint may not be the same as the one stored in SharePoint (which is called the internal field name), especially when you have spaces in your column names. For instance, if you create a new column called “Product Description” and the internal field name in SharePoint database will be “Product_x0020_Description”, and your ASP.net application should use the internal field name to retrieve the value of the column.
It seems that you can just replace the space in the column name with “_x0020_” to get the internal field name, but it does not always work because:
- There is a limit on the length of the internal field name and it will get truncated if the name is too long, and it is a hassle to figure out on which position the truncation happens.
- There are some reserved internal field names that will not change no matter what name you use for the column, for instance, “Title” is a reserved internal field name.
The simplest way to find out the internal field name to click “List” under the “List Tools” tab, then click “List Settings”. Then hover your mouse over the column of your interest, and in the status bar of the browser you will see a link with the internal field name in it.
What if you don’t have access to the SharePoint list directly? In that case, you can programmatically print out all the internal names of a SharePoint list, then you can refer to the following snippet to do it via SharePoint Client Application Library:
You need to add “using SP = Microsoft.SharePoint.Client” in your code.
SP.FieldCollection collField = oProviderList.Fields;
StringBuilder sb = new StringBuilder();
foreach (SP.Field oField in collField)
sb.Append("Field Name: ");
this.Label1.Text = sb.ToString(); // Display all internal field names with a Label control
Here oProviderList is a SharePoint List object returned by GetByTitle() function call.
Now you can print out the output as a future reference. Hope this helps.