1

I try to create a new field programmatically. See code below. This type of field has a maximum of 255 characters. I would like to have more characters, like the page-content field. Which type do I need to use in code?

web.Fields.Add("IntroductionText", SPFieldType.Note, true);

2 Answers 2

3

You can use the Field type HTML.

Here is a XML markup of that field:

<Field ID="{E2CC0231-FA6C-4F90-839C-118C304DFCF1}" StaticName="PMediaDescription" 
Name="PMediaDescription" DisplayName="MediaDescription" Type="HTML" RichText="TRUE"
RichTextMode="ThemeHtml" Group="Site Columns" UnlimitedLengthInDocumentLibrary ="TRUE" />

the real key here is: UnlimitedLengthInDocumentLibrary ="TRUE"

This field type is not accessible in the SPFieldType enumeration though. Try to still use SPFieldType.Note, and then set the property for UnlimitedLengthInDocumentLibrary to true

Documentation of the field types here: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfieldtype.aspx

More field types and markup examples here: http://sharpointpractice.blogspot.se/2011/08/sharepoint-field-types-elementsxml.html

1
  • Glad to hear that! :) Commented Sep 19, 2013 at 8:08
0

you have to create a custom field type as SQLType

Look here

1) Change the ParentType from Text to Note in you fldtypes_custom.xml file

    <Field Name="TypeName">MyPeoplePicker</Field>
    <Field Name="ParentType">Note</Field>
    <Field Name="TypeDisplayName">Custom PeoplePicker</Field>
    <Field Name="TypeShortDescription">Custom PeoplePicker</Field>

Represents whether this field type is displayed for inclusion on lists. The possible values are exactly the same as the possible values for the Type attribute of the Field Element (List – Definition) element. If the field type is not derived from another type, then the value is an empty string:

2) That the real tricky thing, change the SQLType Field in the fldtypes_custom.xml from

    <Field Name="SQLType">nvarchar</Field>
    <Field Name="SQLType">ntext</Field>

Optional String. Represents the SQL data type that will be used to store the data in the content database. However you do not use a

     <Field Name="SQLType">

element in your custom field type definitions.

3) Change the inherits in your base class from SPFieldText to SPFieldMultiLineText

1
  • Or use UnlimitedLengthInDocumentLibrary Commented Sep 17, 2013 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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