{"id":114,"date":"2009-06-23T08:17:56","date_gmt":"2009-06-23T08:17:56","guid":{"rendered":"http:\/\/www.myfatblog.co.uk\/?p=114"},"modified":"2009-06-23T08:17:56","modified_gmt":"2009-06-23T08:17:56","slug":"event-handlers-from-code","status":"publish","type":"post","link":"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/","title":{"rendered":"Event Handlers from code."},"content":{"rendered":"<p>Eek.. June already.. I&#8217;ve been on my hols, come back and realised that I&#8217;ve been somewhat remiss in posting to my blog.<\/p>\n<p>So without further ado, I&#8217;ll talk about my current expedition into the realm of SharePoint code. Todays task is EventHandlers from code.<\/p>\n<p>Attaching Event Handlers from code is pretty easy, the SDK shows various methods all of which seem to do the trick. However, I want my Event Handler to have a specific GUID as it&#8217;s ID. The idea behind this is that my management application knows what the different event handler ID&#8217;s are in all the environments.<\/p>\n<p>And this is where my plan has currently fallen apart.<\/p>\n<p>I&#8217;m using the following code to add the event handler (after correctly checking that an event handler of the same name and assembly doesn&#8217;t already exist of course..)<\/p>\n<pre lang=\"csharp\">\r\nif (!itemDeletingExists)\r\n{\r\nSPEventReceiverDefinition deletingReceiver = erdc.Add(new Guid(\"F649A610-2C83-4f11-B73F-A7D1656DEACB\"));\r\ndeletingReceiver.Name = \"ResourceEventsItemDeleted\";\r\ndeletingReceiver.Type = SPEventReceiverType.ItemDeleting;\r\ndeletingReceiver.SequenceNumber = 10000;\r\ndeletingReceiver.Assembly = assm;\r\ndeletingReceiver.Class = nsp;\r\ndeletingReceiver.Update();\r\nreceiverAdded = true;\r\n}\r\n<\/pre>\n<p>When you step through the code above, the event handler is added quite happily and the deletingReceiver.ID = the guid used in the constructor.<\/p>\n<p>So further down my code we grab the collection of event handlers currently held by the content type and sure enough, there is our (in this case 3 of them) event handlers, sitting happily in the collection.<\/p>\n<p>However, if you grab the EventReceiverDefinition for each of them, the .ID is all zeroes&#8230; Is this a bug or intended behaviour? Further investigations ongoing..<\/p>\n<p>Paul.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eek.. June already.. I&#8217;ve been on my hols, come back and realised that I&#8217;ve been somewhat remiss in posting to my blog. So without further ado, I&#8217;ll talk about my current expedition into the realm of SharePoint code. Todays task is EventHandlers from code. Attaching Event Handlers from code is pretty easy, the SDK shows &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[13,16],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Event Handlers from code. - Blog of an overweight SharePoint addict<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Event Handlers from code. - Blog of an overweight SharePoint addict\" \/>\n<meta property=\"og:description\" content=\"Eek.. June already.. I&#8217;ve been on my hols, come back and realised that I&#8217;ve been somewhat remiss in posting to my blog. So without further ado, I&#8217;ll talk about my current expedition into the realm of SharePoint code. Todays task is EventHandlers from code. Attaching Event Handlers from code is pretty easy, the SDK shows &hellip; Continue reading\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog of an overweight SharePoint addict\" \/>\n<meta property=\"article:published_time\" content=\"2009-06-23T08:17:56+00:00\" \/>\n<meta name=\"author\" content=\"Cimares\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@cimares\" \/>\n<meta name=\"twitter:site\" content=\"@cimares\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Cimares\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\",\"name\":\"Event Handlers from code. - Blog of an overweight SharePoint addict\",\"isPartOf\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\"},\"datePublished\":\"2009-06-23T08:17:56+00:00\",\"dateModified\":\"2009-06-23T08:17:56+00:00\",\"author\":{\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#website\",\"url\":\"http:\/\/www.myfatblog.co.uk\/\",\"name\":\"Blog of an overweight SharePoint addict\",\"description\":\"The rantings of a (not so) food obsessed IT consultant!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6\",\"name\":\"Cimares\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"contentUrl\":\"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg\",\"caption\":\"Cimares\"},\"sameAs\":[\"http:\/\/www.myfatblog.co.uk\"],\"url\":\"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Event Handlers from code. - Blog of an overweight SharePoint addict","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/","og_locale":"en_US","og_type":"article","og_title":"Event Handlers from code. - Blog of an overweight SharePoint addict","og_description":"Eek.. June already.. I&#8217;ve been on my hols, come back and realised that I&#8217;ve been somewhat remiss in posting to my blog. So without further ado, I&#8217;ll talk about my current expedition into the realm of SharePoint code. Todays task is EventHandlers from code. Attaching Event Handlers from code is pretty easy, the SDK shows &hellip; Continue reading","og_url":"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/","og_site_name":"Blog of an overweight SharePoint addict","article_published_time":"2009-06-23T08:17:56+00:00","author":"Cimares","twitter_card":"summary_large_image","twitter_creator":"@cimares","twitter_site":"@cimares","twitter_misc":{"Written by":"Cimares","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/","url":"http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/","name":"Event Handlers from code. - Blog of an overweight SharePoint addict","isPartOf":{"@id":"http:\/\/www.myfatblog.co.uk\/#website"},"datePublished":"2009-06-23T08:17:56+00:00","dateModified":"2009-06-23T08:17:56+00:00","author":{"@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.myfatblog.co.uk\/index.php\/2009\/06\/event-handlers-from-code\/"]}]},{"@type":"WebSite","@id":"http:\/\/www.myfatblog.co.uk\/#website","url":"http:\/\/www.myfatblog.co.uk\/","name":"Blog of an overweight SharePoint addict","description":"The rantings of a (not so) food obsessed IT consultant!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.myfatblog.co.uk\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/55ae8f6885bb5b8390dad001f3da83c6","name":"Cimares","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.myfatblog.co.uk\/#\/schema\/person\/image\/","url":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","contentUrl":"http:\/\/www.myfatblog.co.uk\/images\/BlogImages\/About_D057\/TopOfTheWorld.jpg","caption":"Cimares"},"sameAs":["http:\/\/www.myfatblog.co.uk"],"url":"http:\/\/www.myfatblog.co.uk\/index.php\/author\/reginald\/"}]}},"_links":{"self":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/114"}],"collection":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/comments?post=114"}],"version-history":[{"count":0,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/posts\/114\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/media?parent=114"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/categories?post=114"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.myfatblog.co.uk\/index.php\/wp-json\/wp\/v2\/tags?post=114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}