【发布时间】:2015-01-13 03:50:22
【问题描述】:
我们正在尝试创建一个 ItemAdded 事件接收器,它将更新自定义 SharePoint 列表中的创建者(作者)字段。在这个自定义列表中,我们启用了 Item-Lever Permissions,以便用户 A 只能看到他们创建的内容。问题是当另一个用户 (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 类型)
在 Microsoft.SharePoint.Administration.ISPUserCodeExecutionHostProxy.Execute(类型 userCodeWrapperType、Guid siteCollectionId、SPUserToken userToken、字符串 affinityBucketName、SPUserCodeExecutionContext executionContext)
在 Microsoft.SharePoint.UserCode.SPUserCodeExecutionManager.Execute(键入 userCodeWrapperType,SPSite 站点,SPUserCodeExecutionContext executionContext)
在 createdByElevate 中加载和运行事件接收器 createdByElevate.EventReceiver1.EventReceiver1 时出错,Version=1.0.0.0,Culture=neutral,PublicKeyToken=97fddd01b051f985。附加信息如下。服务器遇到内部错误。如需更多信息,请在服务器的 .config 文件中关闭 customErrors。
- 沙盒代码执行请求失败。 - 内部异常:System.Runtime.Remoting.RemotingException:服务器遇到内部错误。有关详细信息,请在服务器的 .config 文件中关闭 customErrors。服务器堆栈跟踪:重新抛出异常
在 [0]:
【问题讨论】:
-
您确定事件接收器已连接并实际运行吗?运行时 ULS 或 Windows 事件日志中是否有任何内容?当您调试代码时,它会抛出任何异常吗?你得帮我们一点忙,给我们一些更多的信息。
-
我想我已经正确地附加了它,在 Visual Studio 中我会点击 F5 并附加并测试。它不会抛出任何我可以看到的错误。我现在会仔细检查 ULS 日志
-
在 ULS 中发现两个错误:
标签: c# sharepoint event-receiver