lalla1 发表于 2015-9-25 12:57:11

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

  
前提
  项目中用到eWebEditor作为在线编辑器替换sharepoint2010自动的多行编辑器,下面以eWebEditor作为自定义字段类型为例来讲述如何用VS2010在sharepoint中创建自定义字段类型。
开发
  1、 首先用VS2010创建一个空的sharepoint2010项目,如下图:

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

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

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



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


  在ascx添加如下代码:
  <%@ Control Language=&quot;C#&quot;%>
  <%@ Assembly Name=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; %>
  <%@ Register TagPrefix=&quot;SharePoint&quot; Assembly=&quot;Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; Namespace=&quot;Microsoft.SharePoint.WebControls&quot; %>
  <%@ Register Assembly=&quot;eWebEditorControl&quot; Namespace=&quot;eWebEditorControl&quot; TagPrefix=&quot;eWebEditorControl&quot; %>
  <SharePoint:RenderingTemplate ID=&quot;EGEWebEditorCtrl_RenderingTemplate&quot; runat=&quot;server&quot;>
  <Template>
  <eWebEditorControl:eWebEditor ID=&quot;EWebEditor1&quot; runat=&quot;server&quot; BasePath=&quot;eWebEditor/&quot;>
  </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
  {
  
  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
  {
  
  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、 自定类型效果图
  
页: [1]
查看完整版本: 如何用VS2010在SharePoint中创建自定义字段类型(以eWebEditor为例)