Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

SPWeb.GetListFromWebPartPageUrl method

Gets the list that is associated with the first Web Part on the specified Web Parts page.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
public SPList GetListFromWebPartPageUrl(
	string pageUrl
)

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.SPList
The list that is associated with the first Web Part on the specified page.
ExceptionCondition
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();
      }
   }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.