问题描述:

深入浅出SharePoint——计算列如何使用Item的ID

 

深入浅出SharePoint——计算列如何使用Item的ID

 

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
 
namespace NCR
{
    class NCRListEventHandler: SPItemEventReceiver
    {
        /// <summary>
        /// Update NCRPrint calculated column so ID column is not blank. Without this new items have ID empty in NCRPrint column
        /// </summary>
        /// <param name="properties"></param>
        public override void ItemAdded(SPItemEventProperties properties)
        {
            UpdateNCRPrintField(properties);
        }
 
        /// <summary>
        /// Without this the ID in the calculated column after update becomes 0 or empty
        /// </summary>
        /// <param name="properties"></param>
        public override void ItemUpdated(SPItemEventProperties properties)
        {
            UpdateNCRPrintField(properties);
        }
 
        private void UpdateNCRPrintField(SPItemEventProperties properties)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite site = new SPSite(properties.SiteId))
                {
                    using (SPWeb web = site.OpenWeb(properties.RelativeWebUrl))
                    {
                        SPField fldNCRPrint = web.Lists.GetList(properties.ListId, false).Fields.GetFieldByInternalName(Helper.FieldNames.NCRPrint.ToString());
                        fldNCRPrint.Update(true);
                    }
                }
            });
        }
    }
}

 

相关文章:

  • 2021-10-28
  • 2022-01-29
  • 2021-06-21
  • 2021-05-20
  • 2022-02-12
  • 2021-07-30
  • 2021-06-13
  • 2021-11-17
猜你喜欢
  • 2021-07-22
  • 2021-10-25
  • 2021-12-24
  • 2021-11-02
  • 2021-11-21
  • 2021-12-29
  • 2021-09-30
相关资源
相似解决方案