How to get Webpart list in asp.net form
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
精彩评论