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);

                    }

                }

            });

        }

    }

}

 

 

你可能感兴趣的:(SharePoint)