I am trying to create an EventReceiver that works for more than one Content Type. When new Content Types are added in future I need the EventReceiver to still keep working.
My content types will always contain two works for the types of Content Type that I need. I need to execute some code when the ListItem is either of these two content types so I am getting the content type name.
I have the following code that checks for the existence of either of the content type names:
bool testStringA;
bool testStringB;
testStringA = sContentType.Contains("MyKeyWordOneInContentTypeName");
testStringB = sContentType.Contains("MyKeyWordTwoInContentTypeName");
if ((testStringA) || (testStringB))
{
//DO SOMETHING BECAUSE THE LIST ITEM IS OF THE CORRECT CONTENT TYPE
}
Is there a better way to do this type of string comparison in code for this type of scenario?
contentTypeID.StartsWith("0x0123456")in your event receiver code.