1

I have a very strange behavior. We are using SSIS to populate SharePoint 2016 list from a SQL data source. For some lists everything works perfect - but for some reason the list items in a few lists are empty. List items are inserted but without any field values. We use the same script component in SSIS. If I set a breakpoint in the script component, the execution stops und I continue everything works fine. I cannot explain this behaviour, hope someone has an idea. I am completly helpless.

This is the code we are using:

public void CreateListItem(string sharePointUrl, string sharePointListname, string domain, string username, string password, Dictionary<string, string> inputOutput)
{
    using (ClientContext clientContext = new ClientContext(sharePointUrl))
    {
        clientContext.Credentials = new NetworkCredential(username, password, domain);
        Web oWebsite = clientContext.Web;

        clientContext.Load(oWebsite, website => website.Lists);
        clientContext.ExecuteQuery();

        List list = clientContext.Web.Lists.GetByTitle(sharePointListname);
        FieldCollection listFields = list.Fields;
        clientContext.Load(listFields, fields => fields.Include(field => field.Title, field => field.InternalName));
        clientContext.ExecuteQuery();

        var itemCreateInfo = new ListItemCreationInformation();
        var listItem = list.AddItem(itemCreateInfo);

        foreach (string fieldTitle in inputOutput.Keys)
        {
            try
            {
                if (fieldTitle == "Titel")
                {
                    listItem["Title"] = inputOutput[fieldTitle].ToString();
                }
                else
                {
                    var field = listFields.FirstOrDefault(f => f.Title == fieldTitle);
                    listItem[field.InternalName] = inputOutput[fieldTitle].ToString();
                }
            }
            catch (Exception ex)
            {
                LogError("Folgendes Feld konnte in der Feldauflistung der Zielliste nicht gefunden werden: " + fieldTitle + ". Exception: " + ex.Message.ToString());
            }
        }

        listItem.Update();
        clientContext.ExecuteQuery();
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.