如何以asp.net形式获取Webpart列表

时间:2010-08-03 09:55:37

标签: asp.net web-parts

我的目的是在asp.net页面中附上webpart列表。在sharepoint网页中,我们可以这样做:

        SPWeb web = SPContext.Current.Web;
        SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(
            Page.Request.Path,
            PersonalizationScope.Shared);
        for (int i = 0; i < webPartManager.WebParts.Count; i++)
        {
            // We can do checking here or whatever we want......
        }

但是如何在asp.net页面中做到这一点? 谢谢。

1 个答案:

答案 0 :(得分:0)

首先将Microsoft.SharePoint.dll添加到ASP.NET Web项目中。然后,您可以使用以下方法获取SPSite和SPWeb:

SPSite mySiteCollection = new SPSite(*<your site url here>*); 
SPWeb site = mySiteCollection.AllWebs[*<your site name>*]; 

您的其余代码将按现在的方式运行:

SPLimitedWebPartManager webPartManager = web.GetLimitedWebPartManager(   
        Page.Request.Path,   
        PersonalizationScope.Shared);   
for (int i = 0; i < webPartManager.WebParts.Count; i++)   
{   
    //Code here...
}

本文还有一些其他细节:Retrieving SharePoint Site Information in an ASP.NET Web Application