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 have a site object. How do I get the webapplication from the site? I do not have spcontext available. I am using SharePoint 2010. I am trying to do this in a feature event reciever when my feature in enabled.

share|improve this question
up vote 7 down vote accepted

If your feature is activated at the SPSite level, you can do the following...

SPSite site = properties.Feature.Parent as SPSite;
SPWebApplication webApp = site.WebApplication;

I'm not near VS2010 to verify, but I believe properties.Feature.Parent is correct.

share|improve this answer
1… < Devs best friend. – James Love Feb 5 '12 at 21:27
+1 Way to go James! – Falak Mahmood Feb 6 '12 at 9:38
Lol. I'd have dropped the link as well, but I was on my phone. – Tim Gabrhel Feb 6 '12 at 14:45

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.