1

We are trying to publish items programmatically, hence we would like to run all the validation rules applicable as per the item template to check, if the sitecore item has no validation errors. Is there anything available out of the sitecore to check this for an item ? We are trying to achive what sitecore does here in content editor, programatically. https://doc.sitecore.com/xp/en/users/102/sitecore-experience-platform/validate-an-item.html

1 Answer 1

0

Found an old answer on SO that still seems to be valid:

var validatorItem = Sitecore.Data.Database.GetDatabase("master").GetItem("/sitecore/system/Settings/Validation Rules/Item Rules/Item/Duplicate Name");
var validator = ValidatorManager.BuildValidator(validatorItem, Sitecore.Context.Item);

validator.Validate(new ValidatorOptions(false));

if(!validator.IsValid)
{
    Response.Write("Error level: " + validator.Result.ToString() + "<br />");
    Response.Write("Error Message: " + validator.Name + "<br />");
}
else
{
    Response.Write("All ok !");
}

Reference here: https://stackoverflow.com/questions/8261765/how-to-validate-an-item-in-code

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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