How to get SPWebApplication from SPWeb?
-
14-11-2019 - |
Pergunta
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
.
Solução
You can try:
SPWeb web = properties.Feature.Parent as SPWeb;
SPWebApplication webApp = web.Site.WebApplication;
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow