0

I want to check if required field in SharePoint list is filled with data or not? Which method or property should i use?

1

While creating list you can mention which all fields are required. Then SharePoint will do the validation on out of the box add/edit forms.

If that is not the case then you can use a Event Reciever which handles ItemAdding event and do the validation. If validation fails you can cancel the event.

0

SharePoint will not do the validation if an item is added by code. It would be best to iterate through all the fields and if that field is not read only & required, check if it's value is null or not. I guess there is no built-in method how to do it. Your best bet would be something like this in an ItemAdding event receiver:

foreach (SPField f in properties.ListItem.Fields) { if (!f.ReadOnlyField && f.Required && properties.AfterProperties[f.InternalName] == null) { //cancel adding item } }

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.