1. 首先创建一个Field 项目CustomFields.
2. 添加三个类文件:FieldAddressValue.cs ,FieldAddress.cs,AddressFieldControl.cs三个文件.
1) FieldAddressValue.cs源代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Web;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace CustomFields
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
class FieldAddressValue : SPFieldMultiColumnValue
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
private const int numberOfFields = 4;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public FieldAddressValue() : base(numberOfFields)
{ }
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public FieldAddressValue(string value) : base(value)
{ }
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string Address
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this[0]; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this[0] = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string Zip
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this[1]; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this[1] = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string City
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this[2]; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this[2] = value; }
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public string Country
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return this[3]; }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
set
{ this[3] = value; }
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
2) FieldAddress.cs源代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using CustomFields.WebControls;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace CustomFields
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
class FieldAddress : SPFieldMultiColumn
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public FieldAddress(SPFieldCollection fields, string fieldName) : base(fields, fieldName)
{ }
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
public FieldAddress(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName)
{ }
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override BaseFieldControl FieldRenderingControl
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
BaseFieldControl fldControl = new AddressFieldControl();
fldControl.FieldName = InternalName;
return fldControl;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override object GetFieldValue(string value)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(string .IsNullOrEmpty(value))
return null;
return new FieldAddressValue(value);
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3) AddressFieldControl.cs源代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;
using System.Web.UI.WebControls;
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
namespace CustomFields.WebControls
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
{
class AddressFieldControl : BaseFieldControl
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
protected TextBox addressBox;
protected TextBox zipBox;
protected TextBox cityBox;
protected TextBox countryBox;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected override string DefaultTemplateName
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
return "AddressFieldRendering";
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override object Value
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
get
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
EnsureChildControls();
FieldAddressValue fieldValue = new FieldAddressValue();
fieldValue.Address = addressBox.Text.Trim();
fieldValue.Zip = zipBox.Text.Trim();
fieldValue.City = cityBox.Text.Trim();
fieldValue.Country = countryBox.Text.Trim();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
return fieldValue;
}
set
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
EnsureChildControls();
FieldAddressValue fieldValue = (FieldAddressValue)value;
addressBox.Text = fieldValue.Address;
zipBox.Text = fieldValue.Zip;
cityBox.Text = fieldValue.City;
countryBox.Text = fieldValue.Country;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public override void Focus()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
EnsureChildControls();
addressBox.Focus();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
protected override void CreateChildControls()
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (Field == null)
return;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
base.CreateChildControls();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (ControlMode == SPControlMode.Display)
return;
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
addressBox = (TextBox)TemplateContainer.FindControl("addressBox");
if (addressBox == null)
throw new ArgumentException("Corrupted AddressFieldRendering template - missing addressBox. ");
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
addressBox.TabIndex = TabIndex;
addressBox.CssClass = CssClass;
addressBox.ToolTip = Field.Title + " Address";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
zipBox = (TextBox)TemplateContainer.FindControl("zipBox");
if (zipBox == null)
throw new ArgumentException("corrupted AddressFieldRendering template - missing zipBox.");
zipBox.TabIndex = TabIndex;
zipBox.CssClass = CssClass;
zipBox.ToolTip = Field.Title + " Zipcode";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
cityBox = (TextBox)TemplateContainer.FindControl("cityBox");
if (cityBox == null)
throw new ArgumentException("corrupted AddressFieldRendering template - missing cityBox.");
cityBox.TabIndex = TabIndex;
cityBox.CssClass = CssClass;
cityBox.ToolTip = Field.Title + " City";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
countryBox = (TextBox)TemplateContainer.FindControl("countryBox");
if (countryBox == null)
throw new ArgumentException("corrupted AddressFieldRendering template - missing countryBox.");
countryBox.TabIndex = TabIndex;
countryBox.CssClass = CssClass;
countryBox.ToolTip = Field.Title + " Country";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
if (ControlMode == SPControlMode.New)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
addressBox.Text = Field.GetCustomProperty("DefaultStreet").ToString();
zipBox.Text = Field.GetCustomProperty("DefaultZip").ToString();
cityBox.Text = Field.GetCustomProperty("DefaultCity").ToString();
countryBox.Text = Field.GetCustomProperty("DefaultCountry").ToString();
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
3. 强名称编译程序集.
4. 添加一个类型定义文件fldtypes_custom.xml.
fldtypes_custom.xml文件内容如下:
<?xml version="1.0" encoding="utf-8"?>
<FieldTypes>
<FieldType>
<Field Name="TypeName">Address</Field>
<Field Name="ParentType">MultiColumn</Field>
<Field Name="TypeDisplayName">Address</Field>
<Field Name="TypeShortDescription">Address (street + nr, zip, city and country)</Field>
<Field Name="UserCreatable">TRUE</Field>
<Field Name="ShowOnListCreate">TRUE</Field>
<Field Name="ShowOnDocumentLibraryCreate">TRUE</Field>
<Field Name="ShowOnSurveyCreate">TRUE</Field>
<Field Name="ShowOnColumnTemplateCreate">TRUE</Field>
<Field Name="FieldTypeClass">CustomFields.FieldAddress,CustomFields, Version=1.0.0.0, Culture=neutral, PublicKeyToken=55a361e8b234515f</Field>
<PropertySchema>
<Fields>
<Field Name="DefaultStreet" DisplayName="Default Street:" MaxLength="50" DisplaySize="30" Type="Text">
<Default>XiaoYuan Road</Default>
</Field>
<Field Name="DefaultZip" DisplayName="Default Zip:" MaxLength="10" DisplaySize="10" Type="Text">
<Default>100027</Default>
</Field>
<Field Name="DefaultCity" DisplayName="Default City:" MaxLength="50" DisplaySize="30" Type="Text">
<Default>Beijing</Default>
</Field>
<Field Name="DefaultCountry" DisplayName="Default Country:" MaxLength="50" DisplaySize="30" Type="Text">
<Default>China</Default>
</Field>
</Fields>
</PropertySchema>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr><Column/></Expr>
<Case Value="">
</Case>
<Default>
<Column SubColumnNumber="0" HTMLEncode="TRUE" />
<HTML><![CDATA[<BR>]]></HTML>
<Column SubColumnNumber="1" HTMLEncode="TRUE"/>
<HTML><![CDATA[ ---- ]]></HTML>
<Column SubColumnNumber="2" HTMLEncode="TRUE"/>
<HTML><![CDATA[<BR>]]></HTML>
<Column SubColumnNumber="3" HTMLEncode="TRUE"/>
</Default>
</Switch>
</RenderPattern>
</FieldType>
</FieldTypes>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
5. 添加一个模板文件AddressFieldRendering.ascx.
AddressFieldRendering.ascx文件内容如下:
<%@ Control Language="C#" Debug="true"%>
<%@ Assembly Name="Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
<SharePoint:RenderingTemplate ID="AddressFieldRendering" runat="server">
<Template>
<table class="ms-form">
<tr>
<td>Address:</td>
<td><asp:TextBox ID="addressBox" MaxLength="255" size="50" runat="server" /></td>
</tr>
<tr>
<td>Zip:</td>
<td><asp:TextBox ID="zipBox" MaxLength="10" size="5" runat="server" /></td>
</tr>
<tr>
<td>City:</td>
<td><asp:TextBox ID="cityBox" MaxLength="50" size="15" runat="server" /></td>
</tr>
<tr>
<td>Country:</td>
<td><asp:TextBox ID="countryBox" MaxLength="50" size="15" runat="server" /></td>
</tr>
</table>
</Template>
</SharePoint:RenderingTemplate>
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
6. 部署.
1) 把 程序集CustomFields加入GAC.
2) 把类型定义文件fldtypes_custom.xml拷贝到目录c:\program...\12\TEMPLATE\XML下.
3) 把模板文件AddressFieldRendering.ascx拷贝到目录c:\program...\12\TEMPLATE\CONTROLTEMPLATES下.
4) 重起IIS.
项目文件下载