我想将“添加项的远程事件接收器”附加到每个新列表,因此我想为“添加列表的事件”创建远程事件接收器。请帮忙。
答案 0 :(得分:0)
添加了新库的示例代码供您参考。
private void AppInstalledMethod(SPRemoteEventProperties _properties)
{
using (ClientContext clientContext = TokenHelper.CreateAppEventClientContext(_properties, false))
{
if (clientContext != null)
{
Web web = clientContext.Web;
clientContext.Load(web);
clientContext.Load(clientContext.Site);
clientContext.Load(clientContext.Site.EventReceivers);
clientContext.ExecuteQuery();
EventReceiverDefinitionCreationInformation receiver = new EventReceiverDefinitionCreationInformation();
receiver.EventType = EventReceiverType.ListAdded;
OperationContext op = OperationContext.Current;
Message msg = op.RequestContext.RequestMessage;
receiver.ReceiverUrl = msg.Headers.To.ToString();
receiver.ReceiverName = "EventForNewLibrary";
receiver.Synchronization = EventReceiverSynchronization.Synchronous;
receiver.SequenceNumber = 5000;
clientContext.Site.EventReceivers.Add(receiver);
clientContext.ExecuteQuery();
}
}
}
public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
{
SPRemoteEventResult result = new SPRemoteEventResult();
switch (properties.EventType)
{
case SPRemoteEventType.AppInstalled:
AppInstalledMethod(properties);
break;
case SPRemoteEventType.ListAdded:
using (ClientContext clientContext = TokenHelper.CreateRemoteEventReceiverClientContext(properties))
{
if (clientContext != null)
{
var listID=properties.ListEventProperties.ListId;
//to do
}
}
break;
default:
break;
}
return result;
}