如何从SPWeb获得SPWebApplication?

时间:2011-02-17 13:45:56

标签: c# sharepoint-2010 spweb

所以我在网络 scroped功能(properties.Feature.Parent = SPWeb)内。

如何从此SPWebApplication获取SPWeb

我试过了:

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

但我当然得到一个例外,因为我无法将SPWeb对象转换为SPWebApplication

1 个答案:

答案 0 :(得分:16)

您可以尝试:

SPWeb web = properties.Feature.Parent as SPWeb;
SPWebApplication webApp = web.Site.WebApplication;