您的位置:首页 > 其它

如何用VS2010在SharePoint中创建自定义字段类型(以eWebEditor为例)

2013-04-26 13:33 501 查看
 

前提

项目中用到eWebEditor作为在线编辑器替换sharepoint2010自动的多行编辑器,下面以eWebEditor作为自定义字段类型为例来讲述如何用VS2010在sharepoint中创建自定义字段类型。

开发

1、 首先用VS2010创建一个空的sharepoint2010项目,如下图:





指向sharepoint站点,部署为场解决方案,如下图:





2、 在解决方案上添加“映射文件”,指向TEMPLATE\ControlTemplates ,如下图:





选中ControlTemplates 添加”用户控件”,如下图:













添加后需要删除EGEWebEditorCtl.ascx.cs,如下图:









在ascx添加如下代码:

<%@ Control Language="C#"%>

<%@ Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>

<%@ Register Assembly="eWebEditorControl" Namespace="eWebEditorControl" TagPrefix="eWebEditorControl" %>

<SharePoint:RenderingTemplate ID="EGEWebEditorCtrl_RenderingTemplate" runat="server">

<Template>

<eWebEditorControl:eWebEditor ID="EWebEditor1" runat="server" BasePath="eWebEditor/">

</eWebEditorControl:eWebEditor>

</Template>

</SharePoint:RenderingTemplate>

3、 添加映射的XML文件夹和文件,如下图





添加如下XML文件





4、 继承SPFieldMultiLineText,如下图





代码部分:

namespace TCL.EP.ExtendField

{

public class EGEWebEditorFieldType:SPFieldMultiLineText

{

#region//构造

public EGEWebEditorFieldType(SPFieldCollection fields, string fieldName)

: base(fields, fieldName)

{

}

public EGEWebEditorFieldType(SPFieldCollection fields, string typeName, string displayName)

: base(fields, typeName, displayName)

{

}

#endregion

#region//构造控件

/// <summary>

/// 构造控件

/// </summary>

public override BaseFieldControl FieldRenderingControl

{

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]

get

{

BaseFieldControl fieldControl = new EGEWebEditorFieldTypeControl();

fieldControl.FieldName = this.InternalName;

return fieldControl;

}

}

#endregion

}

}

5、 继承BaseFieldControl,如下图:





代码部分:

namespace TCL.EP.ExtendField

{

public class EGEWebEditorFieldType:SPFieldMultiLineText

{

#region//构造

public EGEWebEditorFieldType(SPFieldCollection fields, string fieldName)

: base(fields, fieldName)

{

}

public EGEWebEditorFieldType(SPFieldCollection fields, string typeName, string displayName)

: base(fields, typeName, displayName)

{

}

#endregion

#region//构造控件

/// <summary>

/// 构造控件

/// </summary>

public override BaseFieldControl FieldRenderingControl

{

[SharePointPermission(SecurityAction.LinkDemand, ObjectModel = true)]

get

{

BaseFieldControl fieldControl = new EGEWebEditorFieldTypeControl();

fieldControl.FieldName = this.InternalName;

return fieldControl;

}

}

#endregion

}

}

注意事项:

1、 eWebEditor的DLL必须拷贝到对应站点下的bin下。提示无法找到对应的依赖项,否则不起作用。如下错误:





2、 其他相关的js和CSS也必须拷贝到对应站点下,如果发布到_layouts下或Templates下提示无法找到:404 NOT Found.





3、 必须购买正版,正版的支持word,excel,wps文档导入,图片自动上传,格式基本不变。如下图:





4、 自定类型效果图



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: