Sharepoint - Is there a way to see if an SPField was created by a user?
There are two possibilities here:
1) You need to determine if field is completely custom (added to list by a user from GUI). You can use SourceId property for this purpose. You will get Url, starting with "http://schemas.microsoft.com" for standard fields, and some random GUIDs for custom fields.
Sample code:
SPField field = // get your field from a list or content type here
if (!field.SourceId.StartsWith("http://"))
{
// do your action for completely custom fields
}
2) You need to determine if field is non-system. There are many system fields, usually filled up with some meta information, and they are usually hidden from list management GUI, but they are in your list, internally. You can use FromBaseType property for this purpose, it will be true for all system fields.
Sample code:
SPField field = // get your field from a list or content type here
if (!field.FromBaseType)
{
// do your action for "valuable" fields (non-system)
}
For testing, I created list "Contacts" from standard Contacts list definition on my local SharePoint Portal. I added column "User created column" to it from GUI through [List settings].
After this, I run following PS script ($l stores my SPList object):
$l.Fields | select StaticName, FromBaseType, SourceId
And got following result:
Is a given field one of SharePoint's built in field