I have looked far and wide with no success to find anything that can tell me definitively that you can or cannot get web context in an Event Handler. Apparently it is standard with ASP.NET web applications that if you need to reference a custom Class Library assembly that needs web context, all you need to do within that assembly is add a reference to System.Web and write code that accesses HttpContext.Current. The web context will supposedly be inherited by the assembly from the web application that is referencing it and running inside of IIS. I tried this – SharePoint returns Nothing.
So unless somebody can show me the way, I have to wonder why SharePoint is blocking this – or why the SharePoint team decided not to go the extra mile. Being able to better interact with the user would open up Event Handler solutions to create a better experience with SharePoint for advanced business applications.
BTW – if you plan on working with Event Handlers in Survey Lists, they work a little differently compared to other lists. If your Survey has a page break, clicking Next will trigger the ItemAdded event! Further page breaks call ItemUpdated, and ItemAdded isn’t even called when the final question is answered – ItemUpdated is called again. To handle this, look at evaluating any of these properties to determine whether the user has fully completed the survey:
- SPListItem.HasPublishedVersion (True when finished)
- SPListItem.Level (1 or “Published“)
- SPListItem.MissingRequiredFields (could be handy in validation scenarios)
You must log in to post a comment.