Take the 2-minute tour ×

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

1 Answer 1

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


