Friday, September 26, 2008

Unlimited length text field

SharePoint 2007 SPFieldMultiLineText is limited to 255 characters. How do we bypass this restriction?

We need to create a new field that inherits from SPFieldMultiLineText. and create your own FLDTYPES.XML file.

First We have to create custom field
public class CustomMultilineField : SPFieldMultiLineText
{
#region SPField Constructors
public CustomMultilineField(SPFieldCollection fields, string fieldName) : base(fields, fieldName)
{

}

public CustomMultilineField(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName)
{

}
#endregion

public new string GetFieldValueAsHtml(object value, SPListItem item)
{
string html = base.GetFieldValueAsHtml(value, item);
return html.Replace("CreateWebPage", "CreateCustomPage");
}

public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fieldControl = new CustomMultilineFieldField();
fieldControl.FieldName = InternalName;
return fieldControl;
}
}
}

Render a Control


public class CustomMultilineFieldField : NoteField
{
protected override void RenderFieldForDisplay(HtmlTextWriter output)
{
CustomMultilineField field = (CustomMultilineField) Field;
if (field != null)
{
if (field.CustomMultilineFieldLinking)
{
output.Write("<div class=\"ms-CustomMultilineFieldcontent\">");
output.Write(field.GetFieldValueAsHtml(ItemFieldValue, ListItem));
output.Write("<p></p></div>");
return;
}
}
else
{
return;
}
base.RenderFieldForDisplay(output);
}
}

Create a definition file

<FieldType>
<Field Name="TypeName">CustomMultilineField</Field>
<Field Name="ParentType">Note</Field>
<Field Name="TypeDisplayName">
CustomMultilineFieldField
</Field>
<Field Name="TypeShortDescription">
CustomMultilineFieldField supports custom page
</Field>
<Field Name="UserCreatable">FALSE</Field>
<Field Name="ShowInListCreate">FALSE</Field>
<Field Name="ShowInSurveyCreate">FALSE</Field>
<Field Name="ShowInDocumentLibraryCreate">FALSE</Field>
<Field Name="ShowInColumnTemplateCreate">FALSE</Field>
<Field Name="Sortable">FALSE</Field>
<Field Name="Filterable">FALSE</Field>
<Field Name="FieldTypeClass">IdeSeg.SharePoint.CustomMultilineFields.CustomMultilineField.CustomMultilineField,IdeSeg.SharePoint.CustomMultilineFields,Version=1.0.0.0, Culture=neutral, PublicKeyToken=...</Field>
</FieldType>

1 comment:

H Desk said...

it is not workin ya Tarek... when i tried to compile it... it gives errors..?