Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
1.8 kB
1
Indexable
Never
static void ProcessDataForSharePoint(ClientContext context, List targetList, string listName, DataTable databaseData, DataTable excelData)
        {
            foreach (DataRow row in databaseData.Rows)
            {
                ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
                ListItem newItem = targetList.AddItem(itemCreateInfo);

                foreach (DataRow mappingRow in excelData.Rows)
                {
                    string databaseColumn = mappingRow["DatabaseColumn"].ToString();
                    string sharePointColumn = mappingRow["SharePointColumn"].ToString();
                    if (sharePointColumn.ToLower() == "title")
                    {
                        //string columnValue = row[databaseColumn] as string;
                        string userFirstName = row["UserFirstName"] as string;
                        string userLastName = row["UserLastName"] as string;
                        string columnValue = $"{userFirstName} {userLastName}".Trim();
                        if(columnValue == null || columnValue == "")
                        {
                            columnValue = row["OrganizationName"] as string;
                        }
                        Console.WriteLine(columnValue);

                    }
                    else
                    {
                        string columnValue = row[databaseColumn] as string;
                        newItem[sharePointColumn] = columnValue;
                        Console.WriteLine(columnValue);
                    }
                    
                }

                //newItem.Update();
            }

            //context.ExecuteQuery();

        }
Leave a Comment