我的目的是在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页面中做到这一点? 谢谢。
答案 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