I have some code where I am going through all of the Fields that belong to a content type. I'm curious if there is a way to check to see if the SPField was created by a user or if it is a system field like Created Date or Title.
|
|
||||
|
|
|
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:
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:
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):
And got following result:
|
|||||
|
|
|
|||
|
|
One note is that these solutions are not failsafe. Some fields are created using OM, some fields that are defined in XML also specify as the SourceID but are not built-in. The short answer is simply 'no, you cannot'. |
|||
|
|
