sharepointrequestsharepoint-onlineevent-receiversharepoint-addin

SharePoint online - intercept document request when document clicked


I am working on this project where it includes hosted app with SharePoint online and a dozen of other things.

When a user goes to a document library, and clicks on the name of a document of specific type, the user gets redirected to the hosted app where there is a logic to do something on the document.

How are they implementing the part of "when user clicks on document, user will be redirected to app" ?

I checked httpmodules and couldn't find anything, I also checked remote event receivers and couldn't find anything..maybe I am not searching properly in the large C# solutions they have, or maybe there is another way to implement this..I need help to figure that out.


Solution

  • You would typically add JavaScript to the library page that finds the <a> tags for the documents with your file extensions, and then replaces the "onclick" with your custom code.

    You could also intercept the JavaScript function used by SharePoint and add your additional logic. (do a web search for "SharePoint coreinvoke")

    Disclaimer: most of what you will find is for the "Classic experience". The SharePoint Online "modern experience" changes all of the rules!