2

I am having the same issue as this thread here : SPListDataValidationException in an event receiver on a task list with Overdue tasks.

When I use item.Update();, an exception is thrown "The following error occurred: Microsoft.SharePoint.SPListDataValidationException: List data validation failed. ".

Now I would like to disable the column validation before the item update and then re-enable it after the update.

Is this possible? I cannot find any useful documentation in msdn.

1

We can't disable the validation, instead we can follow the below steps to achieve that,

  1. Temporarily remove the column validation
  2. Update the value to the fields
  3. Set back the validation to the column

Sample Code:

//Get the Field object and temporarily store & remove the column validation

SPField fld = list.Fields["FieldName"];
string tempValidationFormula = fld.ValidationFormula;
string tempValidationMessage = fld.ValidationMessage;
fld.ValidationFormula = "";
fld.ValidationMessage = "";
fld.Update(true);

//Update the ListItem without validation
SPListItem lstitem = list.GetItemById(1);
lstitem["FieldName"]="Value with out validation";
lstitem.Update();

//Setback the validation to the column
fld.ValidationFormula = tempValidationFormula;
fld.ValidationMessage = tempValidationMessage;
fld.Update(true);

list.Update();

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.