zoukankan      html  css  js  c++  java
  • Sharepoint 自定义字段

    SharePoint已经为一般用户和开发者提供了非常好的可重用的能力。更进一步,你可以定义一个可重用的栏定义,这将为我们带来更大的灵活性。

    下面是创建一个自定义字段类型的总体步骤:

    1.新建SharePoint工程,并添加SharePoint映射文件夹Xml,在Xml的文件名必须以fldtypes_开头,否则不能识别。

    2. 添加自定义字段类(RoyCustomField),代码主要重载 protected override void CreateChildControls(),

    如果要设置默认值请Override DefaultValue,如果要验证格式是否正确 请Override GetValidatedString

    如下:

    namespace RoyCustomField
    {
        public class RoyCustomField : SPFieldText
        {
            protected TextBox txtField;
            public RoyCustomField(SPFieldCollection field, string strFieldName)
                : base(field, strFieldName)
            {
            }
            public RoyCustomField(SPFieldCollection field, string strFieldName, string strDispName)
                : base(field, strFieldName, strDispName)
            {
            }
    
            public override string DefaultValue
            {
                get
                {
    
                    return "Roy";
                }
            }
         
            public override BaseFieldControl FieldRenderingControl
            {
                get
                {
                    BaseFieldControl fc = new RoyText();
                    fc.FieldName = this.InternalName;
                    return fc;
                }
            }
    
            public override string GetValidatedString(object value)
            {
                if (!value.ToString().ToUpper().StartsWith("Roy"))
                {
                    throw new SPFieldValidationException("内容必须以Roy开头!");
                }
    
                return value.ToString();
            }
        }
    
    
        public class RoyText : BaseFieldControl
        {
    
            protected TextBox txtRoy;
            protected override void CreateChildControls()
            {
                base.CreateChildControls();
              this.TemplateContainer.FindControl("txtRoy");
                txtRoy = new TextBox();
                this.Controls.Add(txtRoy);
            }
           
            public override object Value
            {
                get
                {
                    this.EnsureChildControls();
                    return txtRoy.Text;
                }
                set
                {
                    this.EnsureChildControls();
                    txtRoy.Text=(string)this.ItemFieldValue;
                }
            }
    
            protected override string DefaultTemplateName
            {
                get
                {
                    return "RoyTextRenderingTemplate";
                }
            }
        }
    }

    3.定义XML

    <?xml version="1.0" encoding="utf-8" ?>
    <FieldTypes>
      <FieldType>
        <Field Name="TypeName">RoyCustomField</Field>
        <Field Name="ParentType">Text</Field>
        <Field Name="TypeDisplayName">RoyCustomField</Field>
        <Field Name="TypeShortDescription">RoyCustomField</Field>
        <Field Name="UserCreatable">TRUE</Field>
        <Field Name="FieldTypeClass">RoyCustomField.RoyCustomField,$SharePoint.Project.AssemblyFullName$</Field>
      </FieldType>
    </FieldTypes>

    4.打包,部署,效果图如下:

  • 相关阅读:
    Gym 102040B Counting Inversion(超级数位dp)
    Educational Codeforces Round 104 (Rated for Div. 2)(A~D)
    2018-2019 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)_组队训练
    线段树板子
    Codeforces Round #700 (Div. 2)
    Codeforces Round #699 (Div. 2)
    Codeforces Round #698 (Div. 2)
    字典树——实现字符串前缀查找(可返回字符串)
    LeetCode146-LRU缓存机制
    用到过的git命令
  • 原文地址:https://www.cnblogs.com/Roy_Cao/p/2637542.html
Copyright © 2011-2022 走看看