カスタム SharePoint リストの作成者 (作成者) フィールドを更新する ItemAdded イベント レシーバーを作成しようとしています。このカスタム リストでは、アイテム レバーのアクセス許可を有効にして、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.PrivateInvoke
(MessageData& msgData, Int32 タイプ) で System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
で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 の読み込みおよび実行中にエラーが発生しました。バージョン = 1.0.0.0、カルチャ = ニュートラル、PublicKeyToken = 97fddd01b051f985。追加情報は以下のとおりです。サーバーで内部エラーが発生しました。詳細については、サーバーの .config ファイルで customErrors をオフにしてください。
- サンドボックス コードの実行リクエストが失敗しました。- 内部例外: System.Runtime.Remoting.RemotingException: サーバーで内部エラーが発生しました。詳細については、サーバーの .config ファイルで customErrors をオフにしてください。サーバー スタック トレース: [0] で例外が再スローされました: