Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

up vote 9 down vote accepted

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:

enter image description here

share|improve this answer
    
This will actually in a .NET application so I need a way to do it using the object model. –  Abe Miessler Apr 12 '11 at 20:32
    
Oh, PowerShell script is only needed for demonstration of property values for different field types. Anyway, added some C# code to make the answer more visual! Hope this helps :) –  Andrey Markeev Apr 12 '11 at 20:54

http://www.pvle.be/2011/01/is-a-given-field-one-of-sharepoints-built-in-field/

share|improve this answer
    
This has the same result, as SourceId-variant in my answer. But in the same time, it is little more elegant solution. So, my personal +1. –  Andrey Markeev Apr 12 '11 at 22:21

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'.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.