sharepoint 2010 自定义字段开发(1) 创建一个简单的列表自定义字段
2013-01-09 15:12
627 查看
在sharepoint 2010 中,最常用的就是对自定义列表或者文档库的使用,创建一个自定义列表或者文档库,添加一些需要的字段,sharepoint 2010 自带了很多不同类型的控件供字段使用,如下图
很多特殊情况下,这些类型控件,不一定能满足我们的需求,所以我们需要扩展更多的控件类型。
1。创建一个framework 3.5的sharepoint project,名称为 CustomFieldTest
添加一个sharepoint 映射文件夹,展开template,添加controltemplates和xml文件夹
添加完成后,如下图
2。在controltemplates文件夹下,添加一个新建项
选择用户控件,名称为CustomFieldTest.TextBoxControlTemplate.ascx,点击添加
3。在该文件中,添加一个renderingtemplate,Template中添加一个TextBox,在代码如下:
<sharepoint:renderingtemplate
id="txtControlRenderingTemplate"
runat="server">
<Template>
<asp:TextBox
ID="txtControl"
TextMode="SingleLine"
runat="server"></asp:TextBox>
</Template>
</sharepoint:renderingtemplate>
4。在xml文件夹中,添加一个xml文件,名称为 fldtypes_CustomFieldTest.xml,这里的名称有一定的规则,就是必须以fldtypes_开头,后面一般是用应用程序名称命名。
代码如下:
<?xmlversion="1.0"encoding="utf-8"
?>
<FieldTypes>
<FieldType>
<FieldName="TypeName">TxtControl</Field>
<FieldName="ParentType">Text</Field>
<FieldName="TypeDisplayName">TxtControl</Field>
<FieldName="TypeShortDescription">TxtControl</Field>
<FieldName="UserCreatable">TRUE</Field>
<FieldName="ShowInColumnTemplateCreate">TRUE</Field>
<FieldName="FieldTypeClass">CustomFieldTest.TextBoxControl,CustomFieldTest,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e32063bdc8e93a7</Field>
</FieldType>
</FieldTypes>
5。创建一个class文件,名称为TextBoxControl.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
namespace CustomFieldTest
{
public
class TextBoxControl :
SPFieldText
{
public TextBoxControl(SPFieldCollection fields,
string fieldName)
: base(fields, fieldName) { }
public TextBoxControl(SPFieldCollection fields,
string typeName, string displayName)
: base(fields, typeName, displayName) { }
public
override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl ctr =
new TextBoxControlFieldControl();
ctr.FieldName = this.InternalName;
return ctr;
}
}
}
}
public class
TextBoxControlFieldControl : BaseFieldControl
{
protected
override string DefaultTemplateName
{
get
{
return
"txtControlRenderingTemplate";
}
}
protected
TextBox txtControl;
protected
override void CreateChildControls()
{
base.CreateChildControls();
txtControl = (TextBox)TemplateContainer.FindControl("txtControl");
}
public
override object Value
{
get
{
this.EnsureChildControls();
return txtControl.Text;
}
set
{
this.EnsureChildControls();
txtControl.Text = ItemFieldValue.ToString();
}
}
}
}
6。部署该程序,我们打开一个自定义列表或者文档库,在创建栏那里,我们就能看到多了一个TextControl控件类型,填写一个test栏位
点击保存后,就在列表中多了一个叫txtControl的字段。
程序下载地址:http://download.csdn.net/download/cxx2325938/4977645
广州京微信息科技有限公司,微软sharepoint解决方案提供商。
很多特殊情况下,这些类型控件,不一定能满足我们的需求,所以我们需要扩展更多的控件类型。
1。创建一个framework 3.5的sharepoint project,名称为 CustomFieldTest
添加一个sharepoint 映射文件夹,展开template,添加controltemplates和xml文件夹
选择controltemplates文件夹 | 选择xml文件夹 |
2。在controltemplates文件夹下,添加一个新建项
选择用户控件,名称为CustomFieldTest.TextBoxControlTemplate.ascx,点击添加
3。在该文件中,添加一个renderingtemplate,Template中添加一个TextBox,在代码如下:
<sharepoint:renderingtemplate
id="txtControlRenderingTemplate"
runat="server">
<Template>
<asp:TextBox
ID="txtControl"
TextMode="SingleLine"
runat="server"></asp:TextBox>
</Template>
</sharepoint:renderingtemplate>
4。在xml文件夹中,添加一个xml文件,名称为 fldtypes_CustomFieldTest.xml,这里的名称有一定的规则,就是必须以fldtypes_开头,后面一般是用应用程序名称命名。
代码如下:
<?xmlversion="1.0"encoding="utf-8"
?>
<FieldTypes>
<FieldType>
<FieldName="TypeName">TxtControl</Field>
<FieldName="ParentType">Text</Field>
<FieldName="TypeDisplayName">TxtControl</Field>
<FieldName="TypeShortDescription">TxtControl</Field>
<FieldName="UserCreatable">TRUE</Field>
<FieldName="ShowInColumnTemplateCreate">TRUE</Field>
<FieldName="FieldTypeClass">CustomFieldTest.TextBoxControl,CustomFieldTest,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=3e32063bdc8e93a7</Field>
</FieldType>
</FieldTypes>
5。创建一个class文件,名称为TextBoxControl.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
namespace CustomFieldTest
{
public
class TextBoxControl :
SPFieldText
{
public TextBoxControl(SPFieldCollection fields,
string fieldName)
: base(fields, fieldName) { }
public TextBoxControl(SPFieldCollection fields,
string typeName, string displayName)
: base(fields, typeName, displayName) { }
public
override BaseFieldControl FieldRenderingControl
{
get
{
BaseFieldControl ctr =
new TextBoxControlFieldControl();
ctr.FieldName = this.InternalName;
return ctr;
}
}
}
}
public class
TextBoxControlFieldControl : BaseFieldControl
{
protected
override string DefaultTemplateName
{
get
{
return
"txtControlRenderingTemplate";
}
}
protected
TextBox txtControl;
protected
override void CreateChildControls()
{
base.CreateChildControls();
txtControl = (TextBox)TemplateContainer.FindControl("txtControl");
}
public
override object Value
{
get
{
this.EnsureChildControls();
return txtControl.Text;
}
set
{
this.EnsureChildControls();
txtControl.Text = ItemFieldValue.ToString();
}
}
}
}
6。部署该程序,我们打开一个自定义列表或者文档库,在创建栏那里,我们就能看到多了一个TextControl控件类型,填写一个test栏位
点击保存后,就在列表中多了一个叫txtControl的字段。
程序下载地址:http://download.csdn.net/download/cxx2325938/4977645
广州京微信息科技有限公司,微软sharepoint解决方案提供商。
相关文章推荐
- sharepoint 2010 创建一个简单的列表自定义字段
- sharepoint 2010 使用自定义列表模版创建列表(1)
- SharePoint 2010开发工具图解系列:Visual Studio 2010创建列表
- SharePoint 2010/2013 创建一个默认值为当前用户的客户化字段
- SharePoint 2013/2010 在一个列表或文档库内移动列表项,文档和文件夹位置而保持last modify by 等系统字段保持不变
- sharepoint 2010 使用自定义列表模版创建列表(1)
- SharePoint 2010 自定义字段开发
- [SharePoint 2010] 自定义字段类型开发(二)
- SharePoint 2010 自定义字段"大写金额"开发
- 基于SharePoint 2010 创建一个简单的工作流
- 使用VS2010开发一个简单的自定义字段类型
- 在 SharePoint 2010 中创建自定义列表定义
- SharePoint 2010 BCS - 简单实例(二)外部列表创建
- 在SharePoint 2010中创建自定义字段类型
- sharepoint 2010 使用自定义列表模版创建列表(2)
- 基于SharePoint 2010 创建一个简单的工作流
- sharepoint 2010 使用自定义列表模版创建列表(2)
- [5月28日的脚本] 在SharePoint 2010列表或者文档库中添加自定义字段
- sharepoint 2016 学习系列篇(12)-自定义列表应用篇-(1)创建一个自定义列表(Create a custom list)
- msdn创建自定义 SharePoint 2010 字段类型