zoukankan      html  css  js  c++  java
  • ItemAdding实现数据验证中文字段,properties.AfterProperties值为null的问题

    最近写事件接收器,发现中文字段如果直接用properties.AfterProperties[“申请人"]这样获取的值为null,无法得到值。后拉忽然发现用英文字段可以得到值。难道中文字段需要编码?经过测试果真如此。

    代码部分如下:

    public override void ItemAdding(SPItemEventProperties properties)
    {
           base.ItemAdding(properties);
           //得到站点
            SPWeb web = properties.OpenWeb();
           //如果web不为空
            if (web != null)
            {
                 //得到列表
                   SPList list = web.Lists[properties.ListId];
                  //如果列表不为空
                   if (list != null)
                  {
                       //得到字段
                       string fieldName = list.Fields.GetField(WorkLeaveConfig.WorkLeave_Title).InternalName;
                       //得到值
                       string WorkTitle = properties.AfterProperties[fieldName] == null ? string.Empty : properties.AfterProperties[fieldName].ToString();
                       //得到值
                       if (WorkTitle.IndexOf("测试") >= 0)
                     {
    
                           properties.ErrorMessage = "无法请假!";
                           properties.Cancel = true;
                      }
                 }
            }
               
     }
    效果图如下:
    clip_image002
  • 相关阅读:
    HTTPS之acme.sh申请证书
    GoAccess日志分析工具
    KVM之CPU虚拟化
    自动化运维之PSSH
    Hadoop+HBase 集群搭建
    SSH + Google Authenticator 安全加固
    查看数据的类型(python)
    在word中,替换多个词语。正则表达式中 [] {} 是可以连用的(python)
    方差分析的前提,与检验,以及球形检验
    清屏处理(汇编)
  • 原文地址:https://www.cnblogs.com/love007/p/2471261.html
Copyright © 2011-2022 走看看