views:

32

answers:

1

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 we want......
        }

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

A: 

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

Brandon Satrom