GSCustomMenuSection

Contents for SharePoint, ReactJS, C#, ASP .Net, JavaScript, JQuery, SQL

Wednesday, March 16, 2016

Retrieve custom fields only from list using CSOM


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);
}

No comments :

Post a Comment