Пример #1
0
        } // EndMethod: SP_Update

        public static void SP_Delete()
        {
            string   message = AO.PrimaryKey.Name + "-" + AO.PrimaryKey.Value + "-" + " Delete Failed" + Environment.NewLine;
            ListItem Entry;
            var      list = ctx.Web.Lists.GetByTitle(AO.Table);

            AO.PrimaryKey.TrueName = SPA.getInternalFieldName(AO.Table, AO.PrimaryKey.Name, ctx);

            // Includes a delete on the primary key's | seperated value
            if (AO.PrimaryKey.Name != "" && AO.PrimaryKey.Value != "")
            {
                AO.Values.Add(new ColumnName(AO.PrimaryKey.Name, AO.PrimaryKey.Value));
            }

            foreach (var item in AO.Values)
            {
                int EID = 0;
                if (item.Name != "" && item.Value == "")
                {
                    EID = SPA.getListItemID(list, item.Name, AO.PrimaryKey.TrueName, ctx);
                }
                else if (item.Name != "" && item.Value != "")
                {
                    EID = SPA.getListItemID(list, item.Value, AO.PrimaryKey.TrueName, ctx);
                }
                if (EID != 0 && EID != -1)
                {
                    Entry = list.GetItemById(EID);
                    Entry.DeleteObject();
                    message = AO.PrimaryKey.Name + "-" + AO.PrimaryKey.Value + "-" + " Deleted Successfully" + Environment.NewLine;
                }
            }
            ctx.ExecuteQuery();
            SPL.Output.Add(message);
        } // EndMethod: SP_Delete
Пример #2
0
        }//End Main

        #region SharePoint Workers

        public static void SP_Update(bool ForceCreate = false)
        {
            string message = AO.PrimaryKey.Name + "-" + AO.PrimaryKey.Value + "-" + " Update Failed" + Environment.NewLine;
            var    list    = ctx.Web.Lists.GetByTitle(AO.Table);

            #region Find REAL Column Names
            AO.PrimaryKey.TrueName = SPA.getInternalFieldName(AO.Table, AO.PrimaryKey.Name, ctx);
            foreach (ColumnName item in AO.Values)
            {
                item.TrueName = SPA.getInternalFieldName(AO.Table, item.Name, ctx);
            }
            #endregion

            int EID = SPA.getListItemID(list, AO.PrimaryKey.Value, AO.PrimaryKey.TrueName, ctx);
            ListItemCreationInformation itemCreateInfo = new ListItemCreationInformation();
            ListItem lstItem;
            if (EID == 0 || ForceCreate == true)
            {
                lstItem = list.AddItem(itemCreateInfo);
                lstItem.ParseAndSetFieldValue(AO.PrimaryKey.TrueName, AO.PrimaryKey.Value);
                EID = lstItem.Id;
            }
            else
            {
                EID     = SPA.getListItemID(list, AO.PrimaryKey.Value, AO.PrimaryKey.TrueName, ctx);
                lstItem = list.GetItemById(EID);
            }
            foreach (ColumnName item in AO.Values)
            {
                if (item.TrueName.Length >= 1)
                {
                    lstItem.ParseAndSetFieldValue(item.TrueName, item.Value);
                    message = AO.PrimaryKey.Name + "-" + AO.PrimaryKey.Value + "-" + " Updated Successfully" + Environment.NewLine;
                }
                else
                {
                    message = item.Name + "-" + item.Value + "-" + " Real Name Lookup Failed" + Environment.NewLine;
                }
                lstItem.Update();
            }
            ctx.ExecuteQuery();
            SPL.Output.Add(message);
        } // EndMethod: SP_Update