Sign up ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I'd like to intercept the event of opening a file/document stored on a SharePoint site (after a user has clicked on a file) and execute some custom code before synchronously proceeding with normal file opening.

Something like this:

  1. user clicks on a file on a site,
  2. call custom code based on the clicked file (e.g. log clicked file information such as name and GUID),
  3. after custom code has completed, proceed with normal opening (content retrieval) of the file (or retry opening without executing custom code).

Is this possible to do using the SharePoint API? If so, how? All help is appreciated.

share|improve this question
    
If you're trying to log who opens files, that can all be done through the built in analytics with logging events, no custom code required. – Paul Leigh Sep 4 '13 at 14:33
    
Thank you, but I'm actually trying to do quite a lot more and custom code is absolutely required (i.e. I want to invoke certain third-party assemblies/API). Logging was just an example to point out that I need specific file information (SPFile object or something similar). – w128 Sep 4 '13 at 14:42

2 Answers 2

up vote 2 down vote accepted

SharePoint itself does not provide what you are looking for but .Net does. It is called an HttpModule and can position itself in the request pipeline in order to 'preview' all incoming requests. Microsoft has an example HttpModule available and you will need to make sure that it is loaded in the web.config prior to the SharePoint handler.

Bear in mind that changing incoming or outgoing data in the pipeline itself can cause other issues, like authentication failures, validation failures and so forth. It may also break caching which can cause scalability issues. However, if you are merely monitoring incoming requests, taking actions outside the pipeline and then passing the unmodified request to SharePoint, it should be safe enough.

share|improve this answer

The auditing policy in SharePoint will guide you to the document opened event, I am not still sure how to go around that, because there is no document opened in SharePoint, but I would start investigating in the auditing feature in SharePoint and how to track its events.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.