Retrieve custom fields only from list using CSOM

Updated: Sep 15, 2020

This blog demonstrates how to retrieve/print only custom fields (user created) from a list using CSOM.

Add two references to your visual studio solution

  • Microsoft.SharePoint.Client.dll &

  • Microsoft.SharePoint.Client.Runtime.dll

string siteURL = "http://server/sites/site";
ClientContext context = new ClientContext(siteURL);
Web oWebSite = context.Web;

context.Load(oWebSite);
context.ExecuteQuery();

//Get the list by title
List employeeList = oWebSite.Lists.GetByTitle("Employee");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "";
ListItemCollection listItems = employeeList.GetItems(camlQuery);

context.Load(employeeList);
context.Load(listItems);
context.Load(employeeList.Fields);
context.ExecuteQuery();

foreach(Field field in employeeList.Fields)
{
    if(!field.FromBaseType)
         Console.WriteLine("{0} - {1} - {2}",field.Title, field.InternalName, field.Hidden);
}

3 views0 comments

Recent Posts

See All

In this blog we will see how to export a list in excel using server side object model. First block we will retrieve all items from the list. This can be done in several ways. You can get all items wit