How to get InternalName in ListEdit Page

In SharePoint the column or field has two names. One is DisplayName, used to view the field name publically in all pages and another is InternalName used internally to refer the Field. This Internal name will be used in CAML Queries, during retreiving inserting and updating the list item.We can’t see this Internal name in any pages normally, but we can do some work around for getting this internalnames, such as writing the code  & look in to the url of the particular field.

Now i giving a simple tip on displaying the InternalName on ListEdit page itself, this will help us in knowing internal name quickly and consume the time when we work up on List and ListItems.

  • For that, we have to edit the ListEdit.aspx page, which is available under <System Folder>:Program FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATELAYOUTS
  • Before going to edit that page, backup that file and open it. This is the screenshot, taken before editing the page,
    Displaying ListEdit Page without Internal Names
  • In the ListEdit page, add the Column as InternalName under Columns section,To add the header for Internalname under Columns section, Search for the following line
    for (Int32 iIndex = 0; iIndex < spFields.Count; iIndex ++ )
  • At first we have to add the header column, for that before the above searched  line there is <TR> tag with three header <TH> tags, add the following <TH> within the <TR> tag,<TH scope=”col”-vh2-nofilter width=25% id=”TH1″>Internal Name</TH>After adding the line, the code look like this,
    <TR>
    <TH scope=”col”-vh2-nofilter width=25% id=”1600″>
    <SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,listedit_columnclicktoedit%>” EncodeMethod=’HtmlEncode’/>
    </TH>
    <TH scope=”col”-vh2-nofilter width=25% id=”1700″>
    <SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,listedit_type%>” EncodeMethod=’HtmlEncode’/>
    </TH>
    <TH scope=”col”-vh2-nofilter colspan=2 id=”1800″>
    <% if (!spList.ContentTypesEnabled) { %>
    <SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,listedit_required%>” EncodeMethod=’HtmlEncode’/>
    <% } else { %>
    <SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,listedit_used_in%>” EncodeMethod=’HtmlEncode’/>
    <% } %>
    </TH>
    <TH scope=”col”-vh2-nofilter width=25% id=”TH1″>Internal Name</TH>
    </TR>
    for (Int32 iIndex = 0; iIndex < spFields.Count; iIndex ++ )
  • And then we have to add the InternalName for each field type, for that
    Search for the following if condition line,

    if (spField.ReadOnlyField && !bCountRelated)

    The above line checks the current field is read only or not, by default the read only fields are User and Calculated Columns

  • If you look in to the page, you can able to see the switch case statement under the if condition. Switch case statement checks the each read-only field type and adding the row contents such as (Display name, field type and Require or not) columns based on the field type,so we have to add the following line (column) within each case statement,

    <TD-vb2><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></TD>

    In this page, spField.InternalName displays the Internal Name for the current field type.

    The above TD tag content ensures that, the each field row has its own Internalname

  • The else condition refers to the non-read only fields, If we add this line <TD-vb2><%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%></TD>, the internal Name will be appeared on all the non-read only field types.
  • After adding all the lines, the code for the if and else condition will be look like this,

    if (spField.ReadOnlyField && !bCountRelated)
    {
    switch (spField.Type)
    {
    case SPFieldType.Calculated:
    rowClass = (rowClass == “”)? “ms-alternating” : “”;
    %>
    <TR>
    <TD-vb2>
    <A ID=”LinkEditField<%= Convert.ToString(iIndex) %>” HREF=”FldEdit.aspx?List=<%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(“B”).ToUpper(), Response.Output);%>&Field=<%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>”> <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%>
    </A>
    </TD>
    <TD-vb2>
    <SharePoint:EncodedLiteral runat=”server” text=”<%$Resources:wss,listedit_calculated%>” EncodeMethod=’HtmlEncode’/>
    </TD>
    <TD colspan=2-vb2>
    <%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%>
    </TD>
    <TD-vb2>
    <%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>
    </TD>

    </TR>
    <%
    break;
    case SPFieldType.User:
    rowClass = (rowClass == “”)? “ms-alternating” : “”;
    %>
    <TR>
    <TD-vb2>
    <A ID=”LinkEditField<%= Convert.ToString(iIndex) %>” HREF=”FldEditEx.aspx?List=<%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(“B”).ToUpper(), Response.Output);%>&Field=<%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>” > <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%></A>
    </TD>
    <TD-vb2><%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%>
    </TD>
    <TD colspan=2-vb2><%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%>
    </TD>
    <TD-vb2>
    <%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>
    </TD>
    </TR>
    <%
    break;
    default:
    if (spField.XPath != null && !spField.Hidden)
    {
    %>
    <TR>
    <TD-vb2>
    <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%>
    </TD>
    <TD-vb2><%SPHttpUtility.HtmlEncode(spField.TypeDisplayName, Response.Output);%></TD>
    <TD colspan=2-vb2>
    <% if ( !spList.ContentTypesEnabled && spField.Required == true ) { %> <IMG SRC=”/_layouts/images/check.gif” alt=”Checked”> <% ; } %>
    <%SPHttpUtility.HtmlEncode(GetUsedIn(spField), Response.Output);%>
    </TD>
    <TD-vb2>
    <%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>
    </TD>
    </TR>
    <%
    }
    break;
    }
    }
    else
    {
    rowClass = (rowClass == “”)? “ms-alternating” : “”;
    %>
    <TR><TD-vb2>
    <%if (Enum.IsDefined(typeof(SPFieldType), spField.TypeAsString) && spField.Type != SPFieldType.Lookup && spField.Type != SPFieldType.User) {%>
    <A ID=”LinkEditField<%= Convert.ToString(iIndex) %>” HREF=”FldEdit.aspx?List=<%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(“B”).ToUpper(), Response.Output);%>&Field=<%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>”> <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%></A>
    <%} else {%>
    <A ID=”LinkEditField<%= Convert.ToString(iIndex) %>” HREF=”FldEditEx.aspx?List=<%SPHttpUtility.UrlKeyValueEncode(spList.ID.ToString(“B”).ToUpper(), Response.Output);%>&Field=<%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>”> <%SPHttpUtility.HtmlEncode(spField.Title,Response.Output);%></A>
    <%}%>
    </TD>
    <TD-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-vb2>
    <%SPHttpUtility.UrlKeyValueEncode(spField.InternalName, Response.Output);%>
    </TD>

    </TR>
    <%
    }

    The final outcome will be as follows,
    Displaying ListEdit Page with Internal Names

To download the listedit.aspx page, click here!

2 thoughts on “How to get InternalName in ListEdit Page

  1. rlaci Reply

    Wow, this is real SharePoint hacking. :)

    In SQL I use a table-valued-function to return list/column details from lists table’s tp_fields xml column.

  2. SCochrane Reply

    Hello,

    I used this very cool one of the things that i noticed is that where you see the TD-vb2 tags and TH-vh2-nofilter it should read TD class=ms-vb2 and TH class=ms-vh2-nofilter. Other than that, it works really nice.

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *