We know Moss All column types in Spfield Class inherited. In the new column type, the default type of the item is "Number". What we need is a read-only number column, so we can use this one.
OpenSDKDocument. The type of this number column isSpfieldnubmer, It also derivesSpfieldcurrencyClass, we also derive a class called readonlycountfield.
I would like to make a complete customFieldBut I have been busy recently. I accidentally deleted half of the last write, and I was so lazy to use this simple method.
Create a new project readonlycountfield. Add a readonlycountfield. CS file and add the following content:
Public Class Readonlycountfield: spfieldnumber
{
Public Readonlycountfield (spfieldcollection fields, String Fieldname)
: Base (Fields, fieldname)
{
This. Showineditform= False;
This. Defaultvalue= "0";
}
Public Readonlycountfield (spfieldcollection fields, String Typename, String Displayname)
: Base (Fields, typename, displayname)
{
This. Showineditform= False;
This. Defaultvalue= "0";
}
Public Override Basefieldcontrol fieldrenderingcontrol
{
Get
{< br> basefieldcontrol Control = New numberfield ();
control. fieldname = base . internalname;
return control;
}
}
}
View SDK Document discovery Field There is a showineditform attribute, which I thought was in the setting, so I didn't need to get this read-only field, but I haven't found it for a long time, so I thought of deriving a new class, change this value in the constructor False . So the only thing we need to do in this file is to set the default value in the constructor. Easy to use ~~ We also reload a fieldrenderingcontrol method, which returns Control , This Control Class inherits the basefieldcontrol class. If you want to customize Field You need to write a basefieldcontrol-derived Control Control. There are a lot of online tutorials. Review SDK The document will find that each Moss Built-in Field There will be a corresponding Control Class
Add anotherFldtypes _ReadonlycountField. xml file
<? XML version = "1.0" encoding = "UTF-8" ?>
< Fieldtypes >
< Fieldtype >
< Field Name = "Typename" > Readonlycountfield </ Field >
< Field Name = "Parenttype" > Number </ Field >
< Field Name = "Typedisplayname" > Read-Only number </ Field >
< Field Name = "Typeshortdescription" > Unmodifiable read-only number </ Field >
< Field Name = "Usercreatable" > True </ Field >
< Field Name = "Showinlistcreate" > True </ Field >
< Field Name = "Showinsurveycreate" > True </ Field >
< Field Name = "Show.cumentlibrarycreate" > True </ Field >
< Field Name = "Showincolumntemplatecreate" > True </ Field >
< Field Name = "Showineditform" > False </ Field >
< Field Name = "Fieldtypeclass" > Readonlycountfield, readonlycountfield, version = 1.0.0.0, culture = neutral, publickeytoken = 239ba512823b3816 </ Field >
</ Fieldtype >
</ Fieldtypes >
This file must start with fldtypes, this defines a type of our custom property. If you are interested in moss Field interested, you can view fldtypes under \ Program Files \ common files \ microsoft shared \ Web Server Extensions \ 12 \ template \ XML. do not modify XML files ...... It's troublesome if something goes wrong.
There is also the value in <field name = "fieldtypeclass">, the first class name with namespace,The second isProgramSet, the last publickeytoken = followed by a strong nameKeyValue. You need to follow the next step to build a strong name before you can know. Use reflector to open the compiledDLL.
Create a strong name for the project, that is, the signature in the project property, hook up the Assembly signature, and then create a newKey, Remove the password protection (not available), and deploy it after compilation.
Create a text file namedInstall. bat, Enter the following content
" % ProgramFiles % \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin \ gacutil.exe " - UF readonlycountfield
" % ProgramFiles % \ Microsoft Visual Studio 8 \ SDK \ V2.0 \ bin \ gacutil.exe " - If Bin \ debug \ readonlycountfield. dll
Copy / Y fldtypes_hitscountfield.xml " % Commonprogramfiles % \ microsoft shared \ Web Server Extensions \ 12 \ template \ XML \ "
Iisreset
Run thisBat,OKAfter the deployment is complete, go to the new column to see if there is a type of "unmodifiable read-only number.