How to get all the fields for the specified content type using CSOM in SharePoint 2013


Namespaces:

using Microsoft.SharePoint.Client;
Assemblies:
Microsoft.SharePoint.Client.dll;
Microsoft.SharePoint.Client.RunTime.dll;
Code Snippet:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;

namespace CSOMSamples
{
class Program
{
static void Main(string[] args)
{
//// String Variable to store the siteURL
string siteURL = "http://c4968397007/";

//// Get the context for the SharePoint Site to access the data
ClientContext clientContext = new ClientContext(siteURL);

//// Get the content type using ID: 0x01003D7B5A54BF843D4381F54AB9D229F98A - is the ID of the "Custom" content Type
ContentType ct = clientContext.Web.ContentTypes.GetById("0x01003D7B5A54BF843D4381F54AB9D229F98A");

//// Gets a value that specifies the collection of fields for the content type
FieldCollection fieldColl = ct.Fields;

clientContext.Load(fieldColl);
clientContext.ExecuteQuery();

//// Display the field name
foreach (Field field in fieldColl)
{
Console.WriteLine(field.Title);
}
Console.ReadLine();
}
}
}


Ebook Download
View all
Learn
View all