Pages

May 2, 2014

Show More Field Info on List Settings Page




I thought it would be useful for the SharePoint site admin to see additional info about the columns in list, so decided to customize the list edit page (/_layouts/listedit.aspx) to display the internal name, ID and validation info for each column.

Previous work:
I found this post where it shows how to display the internal name for columns. The idea is nice but the description was not very clear. So I decided to write a post on how to do it with adding additional column info bu leveraging more properties from SPField class.

Before you begin:
Changes to SharePoint OTB files in not recommended. You can always create your custom page for example: ListEditEx.aspx and redirect to it through a custom navigation link or a ribbon button. But for the sake of simplicity, I am assuming your are working on a dev environment to test this customization.

Steps:
1. Backup the out-of-the-box (original) listedit.aspx file.


2. In page code, look for the following for statement line:
for (Int32 iIndex = 0; iIndex < spFields.Count; iIndex ++ )


3. Add the headers cells in the table row immediately before the for statement from step 2:
<th scope="col" class="ms-vh2-nofilter" width="15%" id="1900">Internal Name</th>
<th scope="col" class="ms-vh2-nofilter" width="25%" id="2000">ID</th>
<th scope="col" class="ms-vh2-nofilter" width="25%" id="2100">Validation Formula</th>

   You can adjust the width parameter for all columns to your needs.


4. In code after the for statement, look for condition:
if ((spField.ReadOnlyField && !bCountRelated && !bMcolLookup) || spList.HasExternalDataSource)


5. Add the following code cells under each switch statement for that condition (from step 4), and inside the Else statement
<td><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></td>
<td><%SPHttpUtility.UrlKeyValueEncode(spField.Id.ToString(), Response.Output);%></td>
<td><%Response.Output.Write(spField.ValidationFormula);%></td>

Notice that you don't want to use the UrlKeyValueEncode() method on the validation formula (last line above) because validation formula contains special characters that needed to be shawn as is.

For example:
Below is the default switch case code where I highlighted the added custom lines.

default:
if (!spField.Hidden)
{
  if (spField.XPath != null || spList.HasExternalDataSource)
  {
%>
    <tr class="<%=rowClass%>">
    <td class="ms-vb2">
       <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%>
    </td>
    <td class="ms-vb2"><%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%></td>
    <td colspan="2" class="ms-vb2">
        <% if ( !spList.ContentTypesEnabled && spField.Required == true ) { %> <img      src="/_layouts/images/check.gif" alt="Checked"> <% ; } %>
        <%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%>
    </td>
    <td><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></td>
    <td><%SPHttpUtility.UrlKeyValueEncode(spField.Id.ToString(), Response.Output);%></td>
    <td><%Response.Output.Write(spField.ValidationFormula);%></td>
    </tr>
<%
   }
}


6. Save the ListEdit.aspx page and test from any list settings to see the additional column info.