SharePoint 2007 : Custom Field Type
-
06-12-2019 - |
質問
I'm trying to create a custom field type in SharePoint 2007, and the steps I did as below:
i) Create a Class Library project in Visual Studio. The code:
public class CustomField : SPFieldText
{
public CustomField(SPFieldCollection fields, string fName)
: base(fields, fName)
{
}
public CustomField(SPFieldCollection fields, string tName, string dName)
: base(fields, tName, dName)
{
}
public override string DefaultValue
{
get
{
return "XXX";
}
}
public override string GetValidatedString(object value)
{
return value.ToString().ToUpper();
}
}
ii) registered the project as strong key name
iii) build project, then drag and drop the dll into GAC
iv) create a XML file, the code:
<FieldTypes>
<FieldType>
<Field Name="TypeName">CustomField</Field>
<Field Name="ParentType">Text</Field>
<Field Name="TypeDisplayName">Custom Field</Field>
<Field Name="TypeShortDescription">My Custom Field</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="FieldTypeClass">ProjectName, CustomField, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXPUBLICKEYXXX</Field>
</FieldType>
</FieldTypes>
v) do iisreset
then I go to SharePoint create a Site Column, I don't see the custom field type I deployed, am I missing any step?
解決
I'd recommend you to use WSP Builder item template for creating Custom Field Types. Just add a project item, and all necessary files will be created automatically.
If you don't want to use WSP Builder, please consider these points:
- XML files for custom field types should be named as "fldtypes_YourFieldName" and placed into TEMPLATE\XML folder.
Looks like you need to swap ProjectName and CustomField in your FieldTypeClass property, to make it look like this:
<Field Name="FieldTypeClass">MyProject.MyFieldTypeClass, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=XXXPublicKeyTokenXXX</Field>
Usually you should provide also FieldControl and field editor control classes
Also, have a look at following MSDN article: