Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get SPWebApplication from SPWeb?

So I'm inside a web scroped feature (properties.Feature.Parent = SPWeb).

How do I get the SPWebApplication from this SPWeb?

I tried:

SPWebApplication webApp = (SPWebApplication)properties.Feature.Parent;

But of course I get an exception because I cannot cast the SPWeb object as an SPWebApplication.

like image 737
Dennis G Avatar asked Feb 17 '11 13:02

Dennis G


1 Answers

You can try:

SPWeb web = properties.Feature.Parent as SPWeb;
SPWebApplication webApp = web.Site.WebApplication;
like image 163
Edwin de Koning Avatar answered Oct 05 '22 09:10

Edwin de Koning