private static void UpdateEditorAndModifiedFieldsProperty(ClientContext userContext, List list, string listName, ref PeoplePickerEdiorModified isEditorModified, bool reset)
        {
            try
            {
                if (list == null)
                {
                    list = userContext.Web.Lists.GetByTitle(listName);
                    Web oweb = userContext.Web;
                    userContext.Load(oweb);
                    userContext.Load(list);
                    userContext.ExecuteQuery();
                }
                FieldCollection fields = list.Fields;
                userContext.Load(fields, flds => flds.Where(field => field.InternalName == "Editor" || field.InternalName == "Modified"));
                userContext.ExecuteQuery();

                foreach (Field oField in fields)
                {
                    if (!reset)
                    {
                        if (oField.InternalName == "Editor" && !oField.ReadOnlyField)
                        {
                            oField.ReadOnlyField = true;
                            isEditorModified.isEditorfieldModified = true;
                            oField.Update();
                        }

                        if (oField.InternalName == "Modified" && !oField.ReadOnlyField)
                        {
                            oField.ReadOnlyField = true;
                            isEditorModified.isModifiedFieldModified = true;
                            oField.Update();
                        }
                    }
                    else
                    {
                        //reset to original status

                        if (oField.InternalName == "Editor" && isEditorModified.isEditorfieldModified)
                        {
                            oField.ReadOnlyField = !oField.ReadOnlyField;
                            oField.Update();
                        }
                        if (oField.InternalName == "Modified" && isEditorModified.isModifiedFieldModified)
                        {
                            oField.ReadOnlyField = !oField.ReadOnlyField;
                            oField.Update();
                        }
                    }

                }
                userContext.ExecuteQuery();

            }
            catch (Exception Ex)
            {
                Logger.LogErrorMessage("Failed Updating readonly fileds in Method  UpdateEditorAndModifiedFieldsProperty() Exception Message--"+Ex.Message, false);
            }
        }
示例#2
0
        private static void UpdateEditorAndModifiedFieldsProperty(ClientContext userContext, List list, string listName, ref PeoplePickerEdiorModified isEditorModified, bool reset)
        {
            try
            {
                if (list == null)
                {
                    list = userContext.Web.Lists.GetByTitle(listName);
                    Web oweb = userContext.Web;
                    userContext.Load(oweb);
                    userContext.Load(list);
                    userContext.ExecuteQuery();
                }
                FieldCollection fields = list.Fields;
                userContext.Load(fields, flds => flds.Where(field => field.InternalName == "Editor" || field.InternalName == "Modified"));
                userContext.ExecuteQuery();

                foreach (Field oField in fields)
                {
                    if (!reset)
                    {
                        if (oField.InternalName == "Editor" && !oField.ReadOnlyField)
                        {
                            oField.ReadOnlyField = true;
                            isEditorModified.isEditorfieldModified = true;
                            oField.Update();
                        }

                        if (oField.InternalName == "Modified" && !oField.ReadOnlyField)
                        {
                            oField.ReadOnlyField = true;
                            isEditorModified.isModifiedFieldModified = true;
                            oField.Update();
                        }
                    }
                    else
                    {
                        //reset to original status

                        if (oField.InternalName == "Editor" && isEditorModified.isEditorfieldModified)
                        {
                            oField.ReadOnlyField = !oField.ReadOnlyField;
                            oField.Update();
                        }
                        if (oField.InternalName == "Modified" && isEditorModified.isModifiedFieldModified)
                        {
                            oField.ReadOnlyField = !oField.ReadOnlyField;
                            oField.Update();
                        }
                    }
                }
                userContext.ExecuteQuery();
            }
            catch (Exception Ex)
            {
                Logger.LogErrorMessage("Failed Updating readonly fileds in Method  UpdateEditorAndModifiedFieldsProperty() Exception Message--" + Ex.Message, false);
            }
        }