Add List fields(Columns) in Sharepoint programmatically using client object model

Referred URL - http://adicodes.com/adding-fields-to-list-with-powershell-in-sharepoint-2010-part2/


  public static Boolean CreateSPListField(string SourceUrl, String listTitle)
        {
            try
            {
                using (ClientContext clientContext = new ClientContext(SourceUrl))
                {
                    clientContext.Credentials = new NetworkCredential(UserName, Password, Domain);
                    List list = clientContext.Web.Lists.GetByTitle(listTitle);

                    Field oField = list.Fields.AddFieldAsXml("", true, AddFieldOptions.AddFieldToDefaultView);
                    clientContext.ExecuteQuery();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }


You May Also Like

0 comments