Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lesagesander/a385ac012f3f7db0b98e to your computer and use it in GitHub Desktop.
Save lesagesander/a385ac012f3f7db0b98e to your computer and use it in GitHub Desktop.
//do not forget to reference officeams.core (http://officeams.codeplex.com) dll to call extension methods.
//create settingslist
hostWebClientContext.Web.AddList(100, new Guid("00bfea71-de22-43b2-a848-c05709900100"), "Settings", false);
//get settings list
var settingsList = hostWebClientContext.Web.GetListByTitle("Settings");
//prepare eventreceiver binding
var eventReceivers = settingsList.EventReceivers;
hostWebClientContext.Load(eventReceivers);
hostWebClientContext.ExecuteQuery();
//since this code example is running in a web service class during AppInstalled event,
//we can get the remoteweb url from the WebOperationContext
//remoteWebUrl will result in: "yourServiceBusName.servicebus.windows.net"
var remoteWebUrl = string.Empty;
if(null != WebOperationContext.Current)
remoteWebUrl = WebOperationContext.Current.IncomingRequest.Headers["Host"];
//little trick to be able to debug our event receiver
#if DEBUG
remoteWebUrl = String.Format("https://{0}/3458491647/3050950848/obj/f44563bb-02a0-4a5b-b2da-737023b5a03e", remoteWebUrl);
#endif
var settingsRerAdded = new EventReceiverDefinitionCreationInformation
{
ReceiverUrl = String.Format("{0}{1}", remoteWebUrl, "SettingsEvents.svc"),
ReceiverName = "SettingsEventReceiverAdded",
Synchronization = EventReceiverSynchronization.Synchronous,
SequenceNumber = 10000,
EventType = EventReceiverType.ItemAdded
};
settingsList.EventReceivers.Add(settingsRerAdded);
settingsList.Update();
hostWebClientContext.Load(settingsList.EventReceivers);
hostWebClientContext.ExecuteQuery();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment