Domanda

È possibile allegare un ricevitore evento remoto al mio elenco esistente nel mio sito, e non all'elenco nella mia app?Immagino no come non riesco a trovare nulla su questo, e penso che questo sarebbe potenzialmente "ferito" SharePoint.

Se ho bisogno di farlo funzionare, ho bisogno di guardare una sandbox o una soluzione di fattoria giusta?

TIA

È stato utile?

Soluzione

Direi che non è possibile allegare un ricevitore di eventi remoto a un elenco nel Web host, perché queste sono in realtà collezioni di siti trasversali.

Nel Web host potresti solo implementare i ricevitori di eventi regolari (mirando a una classe in un assembly) e i ricevitori di eventi remoti prendono l'URL del WCF effettivo come obiettivo, che non esisterebbe nell'host-Web comunque:

<Url>~remoteAppUrl/RemoteEventReceiver1.svc</Url>
.

o

<Url>http://apps.mydomain.com:36511/MyReR.svc</Url>
.

Altri suggerimenti

Sì, è possibile. Basta gestire il ricevitore evento durante l'installazione dell'app, modificando l'attributo della proprietà su true come seminato di seguito.

 Inserire l'immagine Descrizione qui

e quindi scrivi il seguente codice

public SPRemoteEventResult ProcessEvent(SPRemoteEventProperties properties)
        {
            SPRemoteEventResult result = new SPRemoteEventResult();

            switch (properties.EventType)
            {
                case SPRemoteEventType.AppInstalled:
                    HandleAppInstalled(properties);
                    break;
                case SPRemoteEventType.ItemAdded:
                    HandleItemAdded(properties);
                    break;
            }
            return result;
        }

        private void HandleAppInstalled(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext =
                      TokenHelper.CreateAppEventClientContext(properties, false))
            {
                if (clientContext != null)
                {
                    List myList = clientContext.Web.Lists.GetByTitle("Your List Name");
                    clientContext.Load(myList, p => p.EventReceivers);
                    clientContext.ExecuteQuery();
                    bool rerExists = false;

                    foreach (var rer in myList.EventReceivers)
                    {
                        if (rer.ReceiverName == "ItemAddedEvent")
                        {
                            rerExists = true;
                            System.Diagnostics.Trace.WriteLine("Found existing ItemAdded receiver at "
                               + rer.ReceiverUrl);
                        }
                    }
                    if (!rerExists)
                    {
                        EventReceiverDefinitionCreationInformation receiver =new EventReceiverDefinitionCreationInformation();
                        receiver.EventType = EventReceiverType.ItemAdded;


                        receiver.ReceiverUrl = "Your service url";
                        receiver.ReceiverName = "ItemAddedEvent";
                        receiver.Synchronization = EventReceiverSynchronization.Synchronous;
                        myList.EventReceivers.Add(receiver);
                        clientContext.ExecuteQuery();
                        System.Diagnostics.Trace.WriteLine("Added ItemAdded receiver at " + msg.Headers.To.ToString());
                    }
                }
            }
        }
 private void HandleItemAdded(SPRemoteEventProperties properties)
        {
            using (ClientContext clientContext =
              TokenHelper.CreateRemoteEventReceiverClientContext(properties))
            {
                if (clientContext != null)
                {
                    try
                    {
                        List photos = clientContext.Web.Lists.GetByTitle("Your List Name");
                        ListItem item = photos.GetItemById(
                           properties.ItemEventProperties.ListItemId);
                        clientContext.Load(item);
                        clientContext.ExecuteQuery();

                        item["Title"] += "\nUpdated by RER " +
                             System.DateTime.Now.ToLongTimeString();
                        item.Update();
                        clientContext.ExecuteQuery();
                    }
                    catch (Exception oops)
                    {
                        System.Diagnostics.Trace.WriteLine(oops.Message);
                    }
                }
            }
        }
.

Spero che questo ti aiuterà.

È possibile solo programmaticamente ma non funziona se si distribuisce.

var eventReceiver = new EventReceiverDefinitionCreationInformation
                     {
                         EventType = EventReceiverType.ItemAdding,
                         ReceiverAssembly = Assembly.GetExecutingAssembly().FullName,
                         ReceiverClass = "RemoteReciverWeb.Services.ContactAddEventReceiver",
                         ReceiverName = "ContactAddEventReceiver",
                         ReceiverUrl = remoteEventEndPointUrl,
                         SequenceNumber = 1000
                     };

clientContext.Load(eventresevers);
.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a sharepoint.stackexchange
scroll top