Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

1 Answer 1

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  
msdn.microsoft.com/en-us/library/… < 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

 
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.