In this post I'm going to show how to create new list using Client Object model.
Step: 1 Add the SharePoint Reference
Refer this article
Step: 2 Add the SharePoint namespace
Step: 3 Here is the sample code
Step: 1 Add the SharePoint Reference
Refer this article
Step: 2 Add the SharePoint namespace
using Microsoft.SharePoint.Client;
Step: 3 Here is the sample code
public string CreateList(string Url, string UserName, string Password, String ListName, string Describtion)
{
try
{
ClientContext context = new ClientContext(Url);
context.Credentials = new NetworkCredential(UserName, Password);Web site = context.Web;//Creating ListListCreationInformation infor = new ListCreationInformation();infor.Description = Describtion;infor.Title = ListName ;infor.TemplateType = 107;// Task ListList list = web.Lists.Add(infor);//Creating Columnsvar RefidfieldXml = "<Field Type=\"Text\" MaxLength=\"100\" DisplayName=\"ReferenceID\" Name=\"ReferenceID\" />";Field RefIDField = list.Fields.AddFieldAsXml(RefidfieldXml, true, AddFieldOptions.DefaultValue);context.ExecuteQuery();return "";}catch (Exception ex){return ex.Message;}}
No comments:
Post a Comment