I have been asking AI for coding solutions and the results are, for lack of a better term, comically tragic. I have had to correct our well-admired AI by telling it that the solution it provided would not work, had class conflicts, or the number of parameters an API had was wrong.
Now, let’s just cut to the chase. Where is a good source of information regarding how to code a Microsoft SharePoint List from C#? A good response to that question would make all my other questions in this post answerable
I have produced some pretty good code that creates a SharePoint List from scratch, defines the columns and, I assume, will load the data.
I would like to design the code such that, if the code is run more than once, it will recognize that the SharePoint List already exists and then bypasses the part of the code that would otherwise create the List and create the columns and go directly to the point where the data is loaded.
That is one option. Another option is to have the code simply run a command that would delete the SharePoint List (if it exists) and start over.
Now, like I said, I have put my faith in Microsoft AI copilot and asked it how to do this, but the solutions it provided have failed and the exceptions thrown suggest to me that the AI did not know what it was talking about.
The code I am using is from a suggestion from Microsoft on how to properly work with SharePoint Lists from here:
https://learn.microsoft.com/en-us/sharepoint/dev/sp-add-ins/using-csom-for-dotnet-standard#using-modern-authentication-with-csom-for-net-standard
Here is the code that does the work in creating the SharePoint List
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);
try
{
// Load the list and execute the query
context.Load(newList);
context.ExecuteQuery();
Console.WriteLine("List created successfully!");
}
catch (Exception ex)
{
}
If requested, I can share more details and dig deeper. Please feel free to ask any questions so that I can clarify more on this topic.