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;
                  }
             }
        }
           
 }
效果图如下:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值