SPWeb.GetListFromWebPartPageUrl Method
Gets the list that is associated with the first Web Part on the specified Web Parts page.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
Parameters
- pageUrl
- Type: System.String
The server-relative URL of a Web Part page, such as /sites/sitecollection/subsite/default.aspx.
Return Value
Type: Microsoft.SharePoint.SPListThe list that is associated with the first Web Part on the specified page.
| Exception | Condition |
|---|---|
| ArgumentNullException |
pageUrl is null. |
| SPException |
pageUrlis not a valid URL. -or- The first Web Part on the specified Web Parts page is not associated with lists. |
This method returns the list that is associated with the first Web Part on the specified Web Parts page. To return the list that is associated with the Web Parts page itself, use the GetList method.
The following example is a console application that demonstrates how to get an SPList object that represents the list that is associated with the first Web Part on the default page of a website.
Note that the example assumes the existence of a site collection with an absolute URL of http://localhost/sites/sitecollection and that this site collection has a website named subsite.
using System; using Microsoft.SharePoint; namespace Test { class ConsoleApp { static void Main(string[] args) { using (SPSite site = new SPSite("http://localhost/sites/sitecollection")) { using (SPWeb web = site.OpenWeb("subsite")) { string pageUrl = "/sites/sitecollection/subsite/default.aspx"; SPList list = web.GetListFromWebPartPageUrl(pageUrl); Console.WriteLine("List URL: {0}", list.RootFolder.ServerRelativeUrl); } } Console.ReadLine(); } } }