12

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.

Dennis G
  • 21,405
  • 19
  • 96
  • 133

1 Answers1

16

You can try:

SPWeb web = properties.Feature.Parent as SPWeb;
SPWebApplication webApp = web.Site.WebApplication;
Rich Bennema
  • 10,295
  • 4
  • 37
  • 58
Edwin de Koning
  • 14,209
  • 7
  • 56
  • 74