private static void CreateLocalEmployeesList()
{
using (var clientContext = sPContext.CreateUserClientContextForSPHost())
{
var query = from list in clientContext.Web.Lists
where list.Title == "Local Employees"
select list;
IEnumerable<List> matchingLists = clientContext.LoadQuery(query);
clientContext.ExecuteQuery();
if (matchingLists.Count() == 0)
{
ListCreationInformation listInfo = new ListCreationInformation();
listInfo.Title = "Local Employees";
listInfo.TemplateType = (int)ListTemplateType.GenericList;
listInfo.Url = "Lists/Local Employees";
List localEmployeesList = clientContext.Web.Lists.Add(listInfo);
Field field = localEmployeesList.Fields.GetByInternalNameOrTitle("Title");
field.Title = "Name";
field.Update();
localEmployeesList.Fields.AddFieldAsXml("<Field DisplayName='Added to Corporate DB'"
+ " Type='Boolean'"
+ " ShowInEditForm='FALSE' "
+ " ShowInNewForm='FALSE'>"
+ "<Default>FALSE</Default></Field>",
true,
AddFieldOptions.DefaultValue);
clientContext.ExecuteQuery();
}
}
}