In one of my SharePoint 2007 projects, I was working with SharePoint fields in code. I have spent quite a bit of time searching for all the classnames and fieldtypes that I needed to identify all different field types. In the table below you can find the most important fields.
| Classname |
Type |
TypeAsString |
TypeDisplayName |
TypeShortDescription |
| Microsoft.SharePoint.SPFieldBoolean |
Boolean |
Boolean |
Yes/No |
Yes/No (check box) |
| Microsoft.SharePoint.SPFieldCalculated |
Calculated |
Calculated |
Calculated |
Calculated (calculation based on other columns) |
| Microsoft.SharePoint.SPFieldChoice |
Choice |
Choice |
Choice |
Choice (menu to choose from) |
| Microsoft.SharePoint.SPFieldComputed |
Computed |
Computed |
Computed |
Computed |
| Microsoft.SharePoint.SPFIeld |
ContentTypeId |
ContentTypeId |
Content Type Id |
Content Type Id |
| Microsoft.SharePoint.SPFieldCurrency |
Currency |
Currency |
Currency |
Currency ($, ¥, €) |
| Microsoft.SharePoint.SPFieldDateTime |
DateTime |
DateTime |
Date and Time |
Date and Time |
| Microsoft.SharePoint.SPFieldFile |
File |
File |
File |
File |
| Microsoft.SharePoint.SPField |
Guid |
Guid |
Guid |
Guid |
| Microsoft.SharePoint.SPFieldNumber |
Integer |
Integer |
Integer |
Integer |
| Microsoft.SharePoint.Portal.WebControls.BusinessDataField |
Invalid |
BusinessData |
Business data |
Business data |
| Microsoft.SharePoint.Publishing.Fields.ContentTypeIdFieldType |
Invalid |
ContentTypeIdFieldType |
Content Type Id |
Content Type Id |
| Microsoft.SharePoint.Publishing.Fields.HtmlField |
Invalid |
HTML |
Publishing HTML |
Full HTML content with formatting and constraints for publishing |
| Microsoft.SharePoint.Publishing.Fields.ImageField |
Invalid |
Image |
Publishing Image |
Image with formatting and constraints for publishing |
| Microsoft.SharePoint.Publishing.Fields.LayoutVariationsField |
Invalid |
LayoutVariationsField |
Variations |
Page Layout Variations |
| Microsoft.SharePoint.Publishing.Fields.LinkField |
Invalid |
Link |
Publishing Hyperlink |
Hyperlink with formatting and constraints for publishing |
| Microsoft.SharePoint.Publishing.Fields.PublishingScheduleEndDateField |
Invalid |
PublishingScheduleEndDateFieldType |
Publishing Schedule End Date |
Publishing Schedule End Date |
| Microsoft.SharePoint.Publishing.Fields.PublishingScheduleStartDateField |
Invalid |
PublishingScheduleStartDateFieldType |
Publishing Schedule Start Date |
Publishing Schedule Start Date |
| Microsoft.SharePoint.Publishing.Fields.SummaryLinkField |
Invalid |
SummaryLinks |
SummaryLinks |
Summary Links data |
| Microsoft.Office.Server.WebControls.FieldTypes.SPFieldTargetTo |
Invalid |
TargetTo |
Audience Targeting |
Audience Targeting |
| Microsoft.SharePoint.SPFieldLookup |
Lookup |
Lookup |
Lookup |
Lookup (information already on this site) |
| Microsoft.SharePoint.SPFieldLookup |
Lookup |
LookupMulti |
Lookup |
Lookup (information already on this site) |
| Microsoft.SharePoint.SPFieldNumber |
Number |
Number |
Number |
Number (1, 1.0, 100) |
| Microsoft.SharePoint.SPFieldRecurrence |
Recurrence |
Recurrence |
Recurrence |
Recurrence |
| Microsoft.SharePoint.SPFieldMultiLineText |
Note |
Note |
Multiple lines of text |
Multiple lines of text |
| Microsoft.SharePoint.SPFieldText |
Text |
Text |
Single line of text |
Single line of text |
| Microsoft.SharePoint.SPFieldUrl |
URL |
URL |
Hyperlink or Picture |
Hyperlink or Picture |
| Microsoft.SharePoint.SPFieldUser |
User |
User |
Person or Group |
Person or Group |
The second column contains the value of SPField.Type. This is one of the values of the SPFieldType enumeration. All fields that have a Type other that “Invalid” can be created by using the Add method of a SPFieldCollection object and passing Name, FieldType (SPFieldType) and Required. The other fields can be added by instantiating an object of the specified class and adding that SPField object to the SPFieldCollection. Below you will find 2 samples:
SPSite site = new SPSite("http://office2007"); SPWeb web = site.OpenWeb();
SPList list = web.Lists["Documenten"];
// Add a new text field
list.Fields.Add("NewTextField", SPFieldType.Text, false);
// Add a new HTML field
HtmlField htmlField = new HtmlField(
list.Fields, "HTML", "NewHTMLField");
list.Fields.Add(htmlField);
The string that is passed as the second parameter in the second sample, is the value in the “TypeAsString” column in the table.