We wanted to add a custom field type inherited from SPFieldMultiLineText and we were able to create the field and deploy.
The field was able to save the values but it was not able to save more that 255 Characters.
To solve the issue we followed the steps below:
1. Inherit the Field Class by SPFieldMultiLineText
public class CustomFieldClass : SPFieldMultiLineText
2. Inherit the Field Control Class (if any) by NoteField
public class CustomFieldControlClass : NoteField
3. In the FieldType_xxx.xml check that these Field values are added or modified accordingly
<Field Name="ParentType">Note</Field>
<Field Name="SQLType">ntext</Field>
4. The Most important setting that was needed for us, since we were using it in a Document
library was that for the Field Class set the follow property to True
this.UnlimitedLengthInDocumentLibrary = true;
We have set this value in the Constructor of the Field Class
Hope this helps. See the example Codes below for reference.
Examples Field Class:
public class MyField : SPFieldMultiLineText
{
public MyField(SPFieldCollection fields, string fieldName) :
base(fields, fieldName)
{
this.RichText = true;
this.RichTextMode = SPRichTextMode.Compatible;
this.UnlimitedLengthInDocumentLibrary = true;
}
public MyField(SPFieldCollection fields, string typeName, string displayName):
base(fields, typeName, displayName)
{
this.RichText = true;
this.RichTextMode = SPRichTextMode.Compatible;
this.UnlimitedLengthInDocumentLibrary = true;
}
public override BaseFieldControl FieldRenderingControl
{
get{
BaseFieldControl fieldControl = new MyFieldControl();
fieldControl.FieldName = this.InternalName;
return fieldControl;
}
}}
Examples Field Class Control:
public class MyFieldControl : NoteField
{protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
if (this.ControlMode == SPControlMode.Edit)
{
//edit controls
}
else
{
//Display controls
}
}
}
Examples FiledType_xxx.xml:
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">MyField</Field>
<Field Name="TypeDisplayName">My Field</Field>
<Field Name="TypeShortDescription">My Custom Field</Field>
<Field Name="FieldTypeClass">MyField, my.Custom.Columns, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxx</Field>
<Field Name="ParentType">Note</Field>
<Field Name="SQLType">ntext</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<RenderPattern Name="DisplayPattern">
<HTML>
<![CDATA[<div id="displayDiv]]>
</HTML>
<Column Name="ID" HTMLEncode="TRUE"/>
<HTML>
<![CDATA[">]]>
</HTML>
<Column HTMLEncode="TRUE"/>
<HTML>
<![CDATA[</div>]]>
</HTML>
</RenderPattern>
</FieldType>
</FieldTypes>
The field was able to save the values but it was not able to save more that 255 Characters.
To solve the issue we followed the steps below:
1. Inherit the Field Class by SPFieldMultiLineText
public class CustomFieldClass : SPFieldMultiLineText
2. Inherit the Field Control Class (if any) by NoteField
public class CustomFieldControlClass : NoteField
3. In the FieldType_xxx.xml check that these Field values are added or modified accordingly
<Field Name="ParentType">Note</Field>
<Field Name="SQLType">ntext</Field>
4. The Most important setting that was needed for us, since we were using it in a Document
library was that for the Field Class set the follow property to True
this.UnlimitedLengthInDocumentLibrary = true;
We have set this value in the Constructor of the Field Class
Hope this helps. See the example Codes below for reference.
Examples Field Class:
public class MyField : SPFieldMultiLineText
{
public MyField(SPFieldCollection fields, string fieldName) :
base(fields, fieldName)
{
this.RichText = true;
this.RichTextMode = SPRichTextMode.Compatible;
this.UnlimitedLengthInDocumentLibrary = true;
}
public MyField(SPFieldCollection fields, string typeName, string displayName):
base(fields, typeName, displayName)
{
this.RichText = true;
this.RichTextMode = SPRichTextMode.Compatible;
this.UnlimitedLengthInDocumentLibrary = true;
}
public override BaseFieldControl FieldRenderingControl
{
get{
BaseFieldControl fieldControl = new MyFieldControl();
fieldControl.FieldName = this.InternalName;
return fieldControl;
}
}}
Examples Field Class Control:
public class MyFieldControl : NoteField
{protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void CreateChildControls()
{
base.CreateChildControls();
if (this.ControlMode == SPControlMode.Edit)
{
//edit controls
}
else
{
//Display controls
}
}
}
Examples FiledType_xxx.xml:
<?xml version="1.0" encoding="utf-8" ?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">MyField</Field>
<Field Name="TypeDisplayName">My Field</Field>
<Field Name="TypeShortDescription">My Custom Field</Field>
<Field Name="FieldTypeClass">MyField, my.Custom.Columns, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxxx</Field>
<Field Name="ParentType">Note</Field>
<Field Name="SQLType">ntext</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<RenderPattern Name="DisplayPattern">
<HTML>
<![CDATA[<div id="displayDiv]]>
</HTML>
<Column Name="ID" HTMLEncode="TRUE"/>
<HTML>
<![CDATA[">]]>
</HTML>
<Column HTMLEncode="TRUE"/>
<HTML>
<![CDATA[</div>]]>
</HTML>
</RenderPattern>
</FieldType>
</FieldTypes>
No comments:
Post a Comment