hello,
i have a list in my sharepoint and i would like to extend it with a new field
how do i create a new Field Type
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Roei BarPosted Aug 10, 2009, 1:20 AM
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\XML\FLDTYPES.XML
the file lookes like this
blabla.SharePoint.CustomFields.RelatedCategoriesField, RealCommerce.SharePoint.CustomFields, Version=1.0.0.0, Culture=neutral, PublicKeyToken=109625d57bdfbe68
this section :
blabla.SharePoint.CustomFields.RelatedCategoriesField, RealCommerce.SharePoint.CustomFields, Version=1.0.0.0, Culture=neutral, PublicKeyToken=109625d57bdfbe68
refers to the FieldClass that you need to build in this manner:
namespace Blabla.SharePoint.CustomFields
{
///
///
public class RelatedCategoriesField : SPFieldMultiLineText
{
public RelatedCategoriesField(SPFieldCollection fields, string fieldName)
: base(fields, fieldName)
{ }
public RelatedCategoriesField(SPFieldCollection fields,
string typeName,
string displayName)
: base(fields, typeName, displayName)
{ }
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fldControl = new RelatedCategoriesFieldControl();
fldControl.FieldName = InternalName;
return fldControl;
}
}
}
}
and the FieldControl:
namespace BlaBla.SharePoint.CustomFields
{
public class RelatedCategoriesFieldControl : AjaxBaseFieldControl
{
#region Members
protected RelatedCategoriesUC m_RelatedCategoriesUC;
protected ResourceMgr m_Resource;
#endregion
#region Properties
public ResourceMgr oResource
{
get
{
if (m_Resource == null)
{
m_Resource = new ResourceMgr(ResourceMgr.ResourceFiles.CmsResources);
}
return m_Resource;
}
}
public override object Value
{
get
{
return m_RelatedCategoriesUC.Value;
}
set
{
m_RelatedCategoriesUC.Value = value;
}
}
#endregion
#region Events
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
// In This Case we load a UserControl
m_RelatedCategoriesUC = Page.LoadControl("~/_CONTROLTEMPLATES/CustomField/RelatedCategoriesUC.ascx") as RelatedCategoriesUC;
m_RelatedCategoriesUC.IsRequired = this.Field.Required;
}
protected override void CreateChildControls()
{
base.CreateChildControls();
//load the usercontrol
this.Controls.Add(m_RelatedCategoriesUC);
}
///
/// if the field is required,
/// Make sure that at least one site was choosen
/// by calling function Validate in the UserControl
///
public override void Validate()
{
bool bIsValid = this.IsValid;
if (this.ControlMode == SPControlMode.Display)
{
return;
}
base.Validate();
if (this.IsValid && this.Field != null && this.Field.Required)
{
//if the field is required, call function Validate in the usercontrol
//to make sure that the field is filled
bIsValid = this.m_RelatedCategoriesUC.Validate();
}
if (bIsValid == false)
{
//field is not valid
this.IsValid = false;
//Init ErrorMessage from Rescource
this.ErrorMessage = oResource.GetValue("RequiredField_ChooseSite");
}
else
{
// The field is not empty or not required.
// The data is valid.
}
}
///
/// special care for display mode
/// show urls and sequences if exisiting
/// (the field is not required, so there can be no selections)
///
///
protected override void RenderFieldForDisplay(System.Web.UI.HtmlTextWriter output)
{
RelatedCategoriesFieldValue oRelatedCategoriesFieldValue;
string sHtml;
if (this.ItemFieldValue != null)
{
//there is a selection- render it by calling function RenderFieldForDisplay of RelatedCategoriesUC
sHtml = m_RelatedCategoriesUC.RenderFieldForDisplay(this.ItemFieldValue.ToString());
output.Write(sHtml);
}
else
{
//no selection
output.Write("none");
}
}
#endregion
}
}
Hope This Helps
Ahmad TibiPosted Aug 10, 2009, 12:21 PM