码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2015-03-08 14:06:30      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

 

前提

项目中用到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、 自定类型效果图

技术分享

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

标签:

原文地址:http://www.cnblogs.com/ningang/p/4321590.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!