{"id":3370,"date":"2011-08-02T06:16:31","date_gmt":"2011-08-02T06:16:31","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/how-to-check-if-a-binary-file-has-been-updated-in-an-spitemeventreceiver\/"},"modified":"2016-07-28T10:50:31","modified_gmt":"2016-07-28T10:50:31","slug":"how-to-check-if-a-binary-file-has-been-updated-in-an-spitemeventreceiver","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/how-to-check-if-a-binary-file-has-been-updated-in-an-spitemeventreceiver\/","title":{"rendered":"How to Check if a Binary File Has Been Updated in an SPItemEventReceiver"},"content":{"rendered":"<p>I&#8217;ve been dealing with a number of item event receivers in SharePoint and I ran across the need to figure out whether or not the binary file associated with an item in a document library is being updated during the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventreceiver.itemupdating.aspx\">ItemUpdating<\/a> event.&#160; I knew there were some additional events in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms462603.aspx\">SPItemEventReceiver<\/a> class, but it turns out that none of them alert you as to when a binary file is actually being updated.&#160; <\/p>\n<p>With the simple option out, I had to turn to a more investigative approach.&#160; So I threw in some code to write out the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventproperties.beforeproperties.aspx\">BeforeProperties<\/a> and <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventproperties.afterproperties.aspx\">AfterProperties<\/a> of the properties parameter passed into the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventreceiver.itemupdating.aspx\">ItemUpdating<\/a> method to see if there was some telltale sign of a binary file update, and there were a few.<\/p>\n<p>So if you want to tell whether or not the binary file has been updated in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventreceiver.itemupdating.aspx\">ItemUpdating<\/a> method, you just have to check if <strong>vti_docstoreversion<\/strong> has a <strong>null<\/strong> value in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/microsoft.sharepoint.spitemeventproperties.afterproperties.aspx\">AfterProperties<\/a> collection.&#160; If it has a value, then the binary file has NOT been updated.<\/p>\n<p>There are some additional properties for which this appears to hold true as well:<\/p>\n<ul>\n<li>vti_docstoreversion<\/li>\n<li>vti_docstoretype<\/li>\n<li>vti_metainfoversion<\/li>\n<li>vti_contentversionisdirty<\/li>\n<li>vti_contenttag<\/li>\n<li>vti_modifiedby<\/li>\n<li>vti_timelastmodified<\/li>\n<\/ul>\n<p>I&#8217;m not sure if they all always hold true, but they appeared to be consistent in what little testing I did.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been dealing with a number of item event receivers in SharePoint and I ran across the need to figure out whether or not the binary file associated with an item in a document library is being updated during the ItemUpdating event.&#160; I knew there were some additional events in the SPItemEventReceiver class, but it&#8230;&hellip;<\/p>\n","protected":false},"author":46738,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[],"class_list":["post-3370","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3370","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/46738"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=3370"}],"version-history":[{"count":2,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3370\/revisions"}],"predecessor-version":[{"id":42065,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/3370\/revisions\/42065"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=3370"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=3370"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=3370"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=3370"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}