How to get SPWebApplication from SPWeb?
Asked Answered
A

1

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.

Andriaandriana answered 17/2, 2011 at 13:45 Comment(0)
I
16

You can try:

SPWeb web = properties.Feature.Parent as SPWeb;
SPWebApplication webApp = web.Site.WebApplication;
Integrated answered 17/2, 2011 at 14:3 Comment(1)
You need following namespace: Microsoft.SharePoint.AdministrationImprobity

© 2022 - 2024 — McMap. All rights reserved.