SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to access query string in ItemAdding event but no luck. I thought I can use HttpContext.Current.Request.QueryString to pull query string but HttpContext.Current object is null under Sandbox. I am aware of using Javascript and hidden field to get the query parameter but I am looking for server side implementation. Is there any workaround to pull query string parameters?

public override void ItemAdding(SPItemEventProperties eventProperties)
    // throwing null exception for HttpContext.Current
    string accountDir = HttpContext.Current.Request.QueryString["AccountDir"];
share|improve this question
up vote 1 down vote accepted

I wonder if the approach of saving the value of HttpContext to a variable inside the constructor, and then using that variable in the event would work?

I'm actually surprised to learn that you can get the HttpContext for -ing events in Farm solutions. I assume there still must be cases where it's null there, e.g. if items are added in a console application.

share|improve this answer
I will surely try this approach though I am bit scare using static variable in event receiver class. Is there any impact of using static context to other users? – Firoz Ansari May 7 '13 at 17:21
I think the part with the static variable was to pass it into ItemAdded from ItemAdding, so probably not needed for you. – lgaud May 7 '13 at 17:37

Your Answer


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.