您的位置:首页 > 其它

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

2013-01-23 15:10 148 查看
问题描述:





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);
}
}
});
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: