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


    前提

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

    开发

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

    clip_image002[14]

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

    clip_image004[5]

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

    clip_image006[5]

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

    clip_image008[4]

    clip_image010[4]

    clip_image012[4]

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

    image

    clip_image016[4]

    在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文件夹和文件,如下图

    clip_image017[4]

    添加如下XML文件

    image

    4、 继承SPFieldMultiLineText,如下图

    image

    代码部分:

    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,如下图:

    SNAGHTML10685d7

    代码部分:

    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下。提示无法找到对应的依赖项,否则不起作用。如下错误:

    clip_image025[4]

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

    clip_image026[4]

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

    clip_image028[4]

    4、 自定类型效果图

    clip_image029[4]

  • 相关阅读:
    寻找大富翁
    C++ STL sort()函数用法
    众数
    平方因子
    Hdu 1089 A+B for Input-Output Practice (I)
    Hdu 1090 A+B for Input-Output Practice (II)
    Hdu 1083 Courses
    Hdu 1069 Monkey and Banana
    Hdu 1062 Text Reverse
    Hdu 1068 Girls and Boys
  • 原文地址:https://www.cnblogs.com/love007/p/3044668.html
Copyright © 2020-2023  润新知