Hi Charles, I sure can. Editing it or presenting it in such a way where company information is no there is going to take time. The code first assumes it is creating the list for the first time and when an exception is thrown if the list already exists, it just loads the list. Here is the code
string listTitle = "TripLegs" ;
string listDescription = "This is a new list created using CSOM";
Microsoft.SharePoint.Client.List? newList = null;
Next, we use the "using" method and start a block like this:
using (var authenticationManager = new AuthenticationManager())
using (var context = authenticationManager.GetContext(site, user, password))
{
context.Load(context.Web, p => p.Title);
await context.ExecuteQueryAsync();
Console.WriteLine($"Title: {context.Web.Title}");
Web web = context.Web;
// Create a new list
ListCreationInformation creationInfo = new ListCreationInformation();
creationInfo.Title = listTitle;
creationInfo.Description = listDescription;
creationInfo.TemplateType = (int)ListTemplateType.GenericList;
newList = web.Lists.Add(creationInfo);
THis is when the try catch block is used if an exception is NOT thrown, then we assume that we are dealing with a list that has not been created yet and the use of the ListCreationInformation class is the proper thing to do. The code in the "TRY" block proceeds to create the columns.
try
{
// Load the list and execute the query
context.Load(newList);
context.ExecuteQuery();
Console.WriteLine("List created successfully!");
FieldCollection fields = newList.Fields;
// set up the columns
#region ColumnHeaders
FieldCreationInformation fieldInfo\_1 = new FieldCreationInformation(FieldType.Number)
{
DisplayName = "TripId",
InternalName = "TripId",
Group = "Custom Columns",
AddToDefaultView = true
};