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.


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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.