最近写事件接收器,发现中文字段如果直接用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;
                  }
             }
        }
           
 }
效果图如下:
ItemAdding实现数据验证--中文字段,properties.AfterProperties值为null的问题

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案