创建具有属性值的MOSS2007自定义字段实例(包括步骤与源代码)
来源:互联网 发布:厦门广电网络 电话 编辑:程序博客网 时间:2024/05/01 14:14
创建具有属性值的MOSS2007自定义字段实例(包括步骤与源代码)
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;
namespace CustomFields
{
class FieldAddressValue : SPFieldMultiColumnValue
{
private const int numberOfFields = 4;
public FieldAddressValue() : base(numberOfFields) { }
public FieldAddressValue(string value) : base(value) { }
public string Address
{
get { return this[0]; }
set { this[0] = value; }
}
public string Zip
{
get { return this[1]; }
set { this[1] = value; }
}
public string City
{
get { return this[2]; }
set { this[2] = value; }
}
public string Country
{
get { return this[3]; }
set { this[3] = value; }
}
}
}
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;
namespace CustomFields
{
class FieldAddress : SPFieldMultiColumn
{
public FieldAddress(SPFieldCollection fields, string fieldName) : base(fields, fieldName) { }
public FieldAddress(SPFieldCollection fields, string typeName, string displayName) : base(fields, typeName, displayName) { }
public override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl fldControl = new AddressFieldControl();
fldControl.FieldName = InternalName;
return fldControl;
}
}
public override object GetFieldValue(string value)
{
if(string .IsNullOrEmpty(value))
return null;
return new FieldAddressValue(value);
}
}
}
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;
namespace CustomFields.WebControls
{
class AddressFieldControl : BaseFieldControl
{
protected TextBox addressBox;
protected TextBox zipBox;
protected TextBox cityBox;
protected TextBox countryBox;
protected override string DefaultTemplateName
{
get
{
return "AddressFieldRendering";
}
}
public override object Value
{
get
{
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();
return fieldValue;
}
set
{
EnsureChildControls();
FieldAddressValue fieldValue = (FieldAddressValue)value;
addressBox.Text = fieldValue.Address;
zipBox.Text = fieldValue.Zip;
cityBox.Text = fieldValue.City;
countryBox.Text = fieldValue.Country;
}
}
public override void Focus()
{
EnsureChildControls();
addressBox.Focus();
}
protected override void CreateChildControls()
{
if (Field == null)
return;
base.CreateChildControls();
if (ControlMode == SPControlMode.Display)
return;
addressBox = (TextBox)TemplateContainer.FindControl("addressBox");
if (addressBox == null)
throw new ArgumentException("Corrupted AddressFieldRendering template - missing addressBox. ");
addressBox.TabIndex = TabIndex;
addressBox.CssClass = CssClass;
addressBox.ToolTip = Field.Title + " Address";
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";
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";
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";
if (ControlMode == SPControlMode.New)
{
addressBox.Text = Field.GetCustomProperty("DefaultStreet").ToString();
zipBox.Text = Field.GetCustomProperty("DefaultZip").ToString();
cityBox.Text = Field.GetCustomProperty("DefaultCity").ToString();
countryBox.Text = Field.GetCustomProperty("DefaultCountry").ToString();
}
}
}
}
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>
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"%>
<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>
6. 部署.
1) 把 程序集CustomFields加入GAC.
2) 把类型定义文件fldtypes_custom.xml拷贝到目录c:/program.../12/TEMPLATE/XML下.
3) 把模板文件AddressFieldRendering.ascx拷贝到目录c:/program.../12/TEMPLATE/CONTROLTEMPLATES下.
4) 重起IIS.
项目文件下载
- 创建具有属性值的MOSS2007自定义字段实例(包括步骤与源代码)
- MOSS2007的自定义字段类型
- MOSS2007自定义WebService(1)-----自定义Webservice的步骤介绍
- Oracle数据库 实例说明:表的创建、重命名、属性/字段/列的添加删除与修改
- Qt自定义控件的创建与初步使用(一)之自定义控件的创建步骤
- Qt自定义控件的创建与初步使用(一)之自定义控件的创建步骤
- moss2007中自定义webpart的安装(部署)方法
- 设计具有社交属性的产品方法步骤详解
- [sql server] 获取指定表的创建脚本,包括表和字段的属性、外键(注释掉的)
- 复制表结构,获取指定表的创建脚本,包括表和字段的属性、外键等
- 在VS2008中创建自定义控件(十四)内镶属性与内联属性的优先级
- 在VS2008中创建自定义控件(十四)内镶属性与内联属性的优先级
- 自定义控件的创建步骤
- 从源代码编译anroid详细步骤(包括错误排查)
- 用于处理缺少信息的字段(具有空值的字段)的表达式
- View自定义属性步骤与分析
- 在WebService中使用具有只读属性的类实例
- -------------------获取当前数据库所有表的外键创建脚本、获取指定表的创建脚本,包括表和字段的属性、外键-----------------------
- Software Development Group Leader
- 利用groovy把表中数据导出成txt或csv
- debian上配置apache2+php5+mysql5遇到的问题
- 微软公布完整搜索战略
- 怎样判断路由器的好坏和选择路由器?
- 创建具有属性值的MOSS2007自定义字段实例(包括步骤与源代码)
- java.lang.reflect.InvocationTargetException axis2 code generator error resolved
- 该内存不能为read或written的解决方案
- 在tomcat中配置Postgres + PostGIS JNDI数据源导致PGgeometry无法正常处理的问题
- How to migrate plug-in mmp file to satisfy new security request
- 思念。。。。
- ASP之最小模块化静态生成
- WSS自定义字段问题:在 RenderPattern 中使用自定义属性
- 自动搜索问题