1

我们正在尝试创建一个 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。

4

2 回答 2

1

您的错误似乎表明您已将其部署为沙盒解决方案。不幸的是,您不能SPSecurity.RunWithElevatedPrivileges在此类部署中使用提升的权限 ( )。您将不得不考虑另一种解决此限制的方法,或者重新部署为Farm 解决方案

于 2011-10-03T13:44:56.973 回答
0

您能否首先验证“提交用户”和“请求者”列是否具有相同的数据类型。我的意思是,如果它们的类型相同,那么它将正常工作。

谢谢,-桑托什

于 2011-10-03T09:19:22.577 回答