I run now this code and got an exception on the first row. How to avoid an exception when the column doesnt exists?

SPField field = contentType.Fields.GetFieldByInternalName("ArticleStartDate2");
if(field != null)
   // do something

1 Answer 1


There is a method on the SPFieldCollection class called ContainsField.

You can use that method to check if the field is available before trying to access it.

EDIT: Also notice that there is another method called ContainsFieldWithStaticName you can use if you only have the field static name.

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.