Many customizer and developer projects require knowing the "internal names" for list and library fields. For example the task list field "% Complete" is internally named "PercentComplete".
Here are a few ways to find the internal name:
- From the browser
- From SharePoint Designer
- Using PowerShell
- Using a C# Console Application
- Using the Client Side Object Model
- Using JavaScript Client Side Object Model and a Content Editor Web Part
Pretty much something for everyone!
From the browser
Permissions needed: Must have Site Owner (Full Control) or Design permissions
This could be a bit tedious if you wanted to check all of the fields, but for just one it's quick.
- Display the list or library and click the List or Library Ribbon
- Click List or Library Settings
- Scroll down to the list of columns and click the column name
- Note the URL for the page… the internal name is listed at the end:
http://………&Field=Author
From SharePoint Designer
Permissions needed: Must have Site Owner (Full Control) or Design permissions (may only need edit permissions in the library holding the web part page… To Do for Mike: need to test this!)
- In SharePoint Designer 2010 open your site and edit a web part page
- Click in a web part zone, click the Insert ribbon tab, click Data View and Empty Data View
- Click "Click here to select a data source" and pick your list
- In the Data Source Details pane mouse over the sample data (or the blank area below the field name) and the XSLT path the field will be displayed. The value after the "@" is the internal name.
Using PowerShell
Permissions needed: Administrator access to the server and permissions to the site (PowerShell is an administrator's tool)
$web = Get-SPWeb http://sharepoint/sites/training/salestraining $list = $web.Lists["Announcements"] $list.fields | select Title, InternalName, Hidden, CanBeDeleted | sort title | ft -AutoSize
As you will most often be interested in the non-hidden fields, you can add a Where to filter them:
$list.fields | select Title, InternalName, Hidden, Sealed, CanBeDeleted | where {$_.Hidden -eq $false} | sort title | ft –AutoSize
Using a C# Console Application
Permissions needed: Administrator access to the server and permissions to the site (the code must run on the server)
using System; using Microsoft.SharePoint; // add a reference to Microsoft.SharePoint // remember to change the Build Platform Target to x64! namespace ConsoleApplication3 { class Program { static void Main(string[] args) { SPSite site = new SPSite("http://sharepoint/sites/Training/"); SPWeb web = site.AllWebs["salestraining"]; SPList list = web.Lists["Announcements"]; Console.WriteLine("Title - Internal Name - Hidden - CanBeDeleted"); foreach (SPField f in list.Fields) { Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted); } site.Dispose(); Console.ReadLine(); } } }
Using the Client Side Object Model
Permissions needed: May only need view permissions in the library holding the web part page… (To Do for Mike: need to test this!)
You can write and run Client Side Object Model (CSOM) code from your local PC and not need access to the SharePoint Servers. The following is a little console application with references added for Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime.
using System; using Microsoft.SharePoint.Client; namespace ConsoleApplication4 { class Program { static void Main(string[] args) { string url = "http://sharepoint/sites/training"; ClientContext context = new ClientContext(url); Web web = context.Web; var list = web.Lists.GetByTitle("Announcements"); context.Load(list.Fields); context.ExecuteQuery(); Console.WriteLine(list.Fields.Count); foreach (Field f in list.Fields) { Console.WriteLine("{0} - {1} - {2} - {3}", f.Title, f.InternalName, f.Hidden, f.CanBeDeleted); } Console.ReadLine(); } } }
Using JavaScript Client Side Object Model and a Content Editor Web Part
Permissions needed: May only need view permissions to view the page… (To Do for Mike: need to test this!)
Steps:
- Open Notepad and copy and paste the code below
- Save the file as GetFieldName.htm
- Upload the file to a library (SiteAssets, Shared Documents, etc.)
- Right-click the uploaded file and copy the shortcut (the URL)
- Go to a web part page or the home page and add a Content Editor Web Part
- Edit the web part and set the Content Link to the URL of the file you just uploaded
- Save your changes and test!
<input type="text" id="ListName" value="Tasks"></input> <button onclick='GetFieldList()'>Get Field List</button> <script type="text/javascript"> function GetFieldList() { var listname = document.getElementById("ListName").value; var ctx = SP.ClientContext.get_current(); this.web = ctx.get_web(); ctx.load(this.web); this.list = web.get_lists().getByTitle(listname); ctx.load(this.list); this.fields = this.list.get_fields(); ctx.load(this.fields); ctx.executeQueryAsync(Function.createDelegate(this, this.getListInfoSuccess), Function.createDelegate(this, this.getListInfoFail)); } function getListInfoSuccess(sender, args) { var fieldEnumerator = this.fields.getEnumerator(); var results=""; while (fieldEnumerator.moveNext()) { var oField = fieldEnumerator.get_current(); if (!oField.get_hidden()) results+= oField.get_title() + " - " + oField.get_internalName() + " - " + oField.get_hidden() + "\n"; } alert(results); } function getListInfoFail(sender, args) { alert('Something failed. Error:'+args.get_message()); } </script>
4 comments:
I've used this pae so many times to get the internal names and it's saved me every time.
Another option:
Go to the "EDIT" form of a Sharepoint list/library, such as a blog post..........and click "VIEW SOURCE" in IE or whatever browser you use to see the HTML code......Sharepoint automatically adds comments in there for the internal field name and field type.
Example:
Haha! Love it! I put the .js on the root and can reference it from any CEWP on any subsite/page I'm working on. Many thanks.
Your javascript works with just read permissions use ExecuteOrDelayUntilScriptLoaded(GetFieldList, "SP.js"); to make sure the get client context isn't null.
I'm creating my own html / view with a list I only have read permission so this was great to find internal name / list names
Thanks!
Post a Comment