Gurinder Kaur

Gurinder Kaur

  • NA
  • 4
  • 5.8k

Add column to list programmatically.code (C#)

Jul 21 2017 5:53 AM
using (ClientContext ctx = new ClientContext(siteUrl))
{
if (siteUrl.ToLower().Contains(_SiteFormat)) ctx.Credentials = new SharePointOnlineCredentials
(userName, pwd);
else ctx.Credentials = new System.Net.NetworkCredential(userName, pwdS);
Web web = ctx.Web;
ListCollection listColl = web.Lists;
ListCreationInformation LCinfo = new ListCreationInformation();
LCinfo.Title = ListName;
LCinfo.TemplateType = (int)ListTemplateType.GenericList;
LCinfo.Description = "First Dynamic List";
listColl.Add(LCinfo);
ctx.Load(listColl);
ctx.ExecuteQuery();
List tList = listColl.GetByTitle(ListName);
FieldCollection fcol = tList.Fields;
FieldType colType = FieldType.Text;
//(error: Parameter overloaded for following line of code) 
  tList.Fields.Add("EmpId", colType, true);
  tList.Update();
Console.WriteLine("Lists on the current site:\n\n");
}
}
 
 
Already tried 'newList.Fields.Add("My Column", FieldType.Text, true);' 
 
 
PLEASE HELP...URGENTLY REQUIRED....Thank you!! 

Answers (2)