我们正在尝试创建一个 ItemAdded 事件接收器,它将更新自定义 SharePoint 列表中的创建者(作者)字段。在这个自定义列表中,我们启用了 Item-Lever Permissions 以便 userA 只能看到他们创建的内容。问题是当另一个用户 (UserB) 为其他人 (UserA) 创建项目时,用户 A 将无法看到该项目。
因此,我们希望将 Request By 字段中的任何内容复制到 Created By 字段。为了到达那里,在少数在线人的帮助下,我们创建了以下事件接收器,但它不起作用。你能告诉我们它有什么问题吗?
using System;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.Workflow;
namespace createdByElevate.EventReceiver1
{
/// <summary>
/// List Item Events
/// </summary>
public class EventReceiver1 : SPItemEventReceiver
{
/// <summary>
/// An item was added.
/// </summary>
public override void ItemAdded(SPItemEventProperties properties)
{
//update base first
base.ItemAdded(properties);
string SiteUrl = properties.Web.Url;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SiteUrl))
{
SPWeb web = site.OpenWeb();
SPList List = web.Lists["listName"];
SPListItem item = List.GetItemById(properties.ListItem.ID);
item["Submit User"] = item["Requested By"];
item.Update();
}
});
}
}
}
在 ULS 日志中发现以下错误:
- 沙盒代码执行请求失败。- 内部异常:System.Runtime.Remoting.RemotingException:服务器遇到内部错误。有关详细信息,请在服务器的 .config 文件中关闭 customErrors。服务器堆栈跟踪:在 [0] 处重新抛出异常:
在 System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
在 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
在Microsoft.SharePoint.Administration.ISPUserCodeExecutionHostProxy.Execute(类型 userCodeWrapperType,Guid siteCollectionId,SPUserToken userToken,字符串 affinityBucketName,SPUserCodeExecutionContext executionContext)
在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.Execute(键入 userCodeWrapperType,SPSite 站点,SPUserCodeExecutionContext executionContext)
在 createdByElevate、Version=1.0.0.0、Culture=neutral、PublicKeyToken=97fddd01b051f985 中加载和运行事件接收器 createdByElevate.EventReceiver1.EventReceiver1 时出错。附加信息如下。服务器遇到内部错误。有关详细信息,请在服务器的 .config 文件中关闭 customErrors。
- 沙盒代码执行请求失败。- 内部异常:System.Runtime.Remoting.RemotingException:服务器遇到内部错误。有关详细信息,请在服务器的 .config 文件中关闭 customErrors。服务器堆栈跟踪:在 [0] 处重新抛出异常: