Previous post basic of Client Side Object Model (CSOM) in this post we will see the implementation.
Here steps to create a new list through code..
Open Visual Studio in your system
Select Console Applciation template and give as name
"CreateList"
Add a Microsoft.Cleint Assembly refrence file in
right side refrence tab in visual studio.
Replace Program.cs with the source code below.
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.SharePoint.Client;
namespace CreateList
{
class Program
{
static void Main(string[] args)
{
// ClientContext - Get the context for the SharePoint Site
ClientContext clientContext = new ClientContext("http:/localhost/");
// Specifies the properties of the new custom list
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = "NewList";
creationInfo.Description = "New list using CSOM";
creationInfo.TemplateType = (int) ListTemplateType.GenericList;
// Create a new custom list
List newList = clientContext.Web.Lists.Add(creationInfo);
// Retrieve the custom list properties
clientContext.Load(newList);
// Execute the query to the server.
clientContext.ExecuteQuery();
// Display the custom list Title property
Console.WriteLine(newList.Title);
Console.ReadLine();
}
}
}
Thank you very
much
Fahadullah Karimi
SharePoint Specialist
Using SharePoint Server Object Model in Windows Application | JavaScript Object Model(JSOM) in SharePoint 2013 |
No comments:
Post a Comment