自定义字段类型与FCKeditor结合

来源:互联网 发布:网络技术交流论坛51zm 编辑:程序博客网 时间:2024/04/30 15:03

LitwareFieldTypes

实现FCKeditor这个多行文本编辑器,作为字段类型,添加到列表的栏里

问题:因为创建的这个字段类型是继承SPFieldMultiLineText,所以它的长度不能超过255字符

 

成功部署在242上,如图

1、创建栏位,选择“文本编辑器”类型

2、看到“说明(文本编辑器)  文本编辑器”

3、新建页面的显示

 

解决问题:

法一:修改数据库

SELECT tp_Fields 

FROM allLists 

WHERE tp_ID = 'a6b094e6-8b4a-4b8e-83a1-cc3be3f2b3f6'

 

法二:修改XML文件

fldtypes_Litware.xml

<?xml version="1.0" encoding="utf-8" ?>

<FieldTypes>

  <FieldType>

    <Field Name="TypeName">CompanySize</Field>

    <Field Name="ParentType">Note</Field>

    <Field Name="TypeDisplayName">文本编辑器</Field>

    <Field Name="TypeShortDescription">文本编辑器</Field>

    <Field Name="UserCreatable">TRUE</Field>

    <Field Name="ShowInListCreate">TRUE</Field>

    <Field Name="ShowInSurveyCreate">TRUE</Field>

    <Field Name="ShowInDocumentLibraryCreate">TRUE</Field>

    <Field Name="ShowInColumnTemplateCreate">TRUE</Field>

    <Field Name="FieldTypeClass">LitwareFieldTypes.CompanySizeField, LitwareFieldTypes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=74bad7277fe0d19e</Field>

       <RenderPattern Name="DisplayPattern">

           <Column/>

       </RenderPattern>

  </FieldType>

</FieldTypes>

 

注意:1、如果修改了fldtypes_Litware.xml,需要在列表设置中,删除旧的栏位,重新创建这个自定义类型的新栏位。这样修改才能生效。

      2<Field Name="ParentType">Note</Field>   Note可以解决字段最大255个字符长度的问题,如果设置Text则字段最大长度为255

    

 

 

工程代码:

 

  除了fldtypes_Litware.xml之外,

 

  LitwareFieldTypes.cs


using System;
using System.IO;
using System.Security.Permissions;
using System.Text;
using System.Xml;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.ComponentModel;
using System.Configuration;
using System.Diagnostics;
using FredCK.FCKeditorV2;
using System.Collections.Generic;

 

namespace LitwareFieldTypes
{

    // example of creating a custom field type
    public class CompanySizeField : SPFieldMultiLineText
    {


        /// <summary>
        /// Override the field rendering control to use the custom TreeList control
        /// </summary>
        ///
        public override Microsoft.SharePoint.WebControls.BaseFieldControl FieldRenderingControl
        {
            get
            {
                BaseFieldControl control = new CompanySizeFieldControl();

                control.FieldName = this.InternalName;
                return control;
            }
        }
        // Validate the string. If not valid, throw an SPFieldValidationException
        //public override string GetValidatedString(object value)
        //{
        //    if (this.Required || value.ToString().Equals(string.Empty))
        //    {
        //        throw new SPFieldValidationException("Company size not assigned");
        //    }
        //    return base.GetValidatedString(value);
        //}

 

        /// <summary>
        /// Null constructor
        /// </summary>
        /// <param name="fields"></param>
        /// <param name="fieldName"></param>

        public CompanySizeField(SPFieldCollection fields, string fieldName)
            : base(fields, fieldName) { }

        public CompanySizeField(SPFieldCollection fields, string typeName, string displayName)
            : base(fields, typeName, displayName) { }


    

 

 


    }

 

 

 

    // custom field type uses helper class to initialize and render control
    public class CompanySizeFieldControl : BaseFieldControl
    {
        protected FCKeditor txtContent;

        public override object Value
        {
            get
            {
                this.EnsureChildControls();
                return this.txtContent.Value;
            }
            set
            {
                EnsureChildControls();
                this.txtContent.Value = (string)this.ItemFieldValue;
            }
        }

        protected override void CreateChildControls()
        {
            if (this.ControlMode == SPControlMode.Display)
            {
                base.CreateChildControls();
            }
            else
            {
                this.txtContent = new FCKeditor();
                this.txtContent.BasePath = "/_layouts/fckeditor/";
                this.txtContent.ToolbarSet = "Default";
                this.txtContent.Width = new Unit("600px");
                this.txtContent.Height = new Unit("300px");
                this.txtContent.ID = "aa";
                this.Controls.Add(this.txtContent);
            }        
        }
    }
}

 

 

 

 

原创粉丝点击