开发者

How to get Webpart list in asp.net form

开发者 https://www.devze.com 2023-01-10 04:38 出处:网络
my intention is to get webpart list attached in asp.net page. In sharepoint web page, we can do like this :

my intention is to get webpart list attached in asp.net page. In sharepoint web page, we can do like this :

        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 w开发者_开发问答e want......
        }

But how to do it in asp.net page ? Thank you.


Start by adding the Microsoft.SharePoint.dll to your ASP.NET web project. Then, you can get the SPSite and SPWeb using the following method:

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

The rest of your code will work as you have it now:

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

This article has some additional detail: Retrieving SharePoint Site Information in an ASP.NET Web Application

0

精彩评论

暂无评论...
验证码 换一张
取 消