• Posted on: 2/4/2015
  • Updated on: 2/4/2015
  • Tags: SharePoint, C#, CSOM, Instruction Framework

SharePoint CSOM: Get list metadata

Get list metadata using client side object model.

This SharePoint client object model script gets the SchemaXml of al list and creates a table of SPField information.

The SchemaXml contains all the list's configuration and properties. The table is for easy visualization.

Try this scripts with the Instruction Workbench: Get SharePoint List Metadata

// ----------------------
//  Get the SchemaXml of a list and
//  and create a DataTable of fields
// ----------------------

using System;
using System.Data;
using System.Linq;
using System.Net;
using xSolon.Instructions.DTO;
using Microsoft.SharePoint.Client;
using xSolon.Instructions;
using xSolon.SP.ManagedClient;

public class SP14Client_Sample : AbstractInstruction
{
	public override void Run()
	{
		var ctx = new SP14ClientHelper().GetContext("http://localhost"
			,SP14AuthenticationType.Windows, this.CredentialCache.First());
	
		var list = ctx.Web.Lists.GetByTitle("ListName");
		
		ctx.Load(list, i => i.SchemaXml, i => i.Fields);
		
		ctx.ExecuteQuery();
		
		var fields = xSolon.Instructions.DTO.SerializationExtensions.GetSerializedList(list.Fields);
		
		ResultTable = xSolon.Instructions.DTO.SerializationExtensions.ListToTable(fields);
		
		var schemaPath = System.IO.Path.GetTempFileName();
		
		this.NotifyInformation(schemaPath);
		
		System.IO.File.WriteAllText(schemaPath, list.SchemaXml);
	}

}


comments powered by Disqus
Loading... Loading ...