Share via


SPWeb.GetListFromWebPartPageUrl method

取得與指定的Web Parts page之第一個網頁組件相關聯的清單。

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'宣告
Public Function GetListFromWebPartPageUrl ( _
    pageUrl As String _
) As SPList
'用途
Dim instance As SPWeb
Dim pageUrl As String
Dim returnValue As SPList

returnValue = instance.GetListFromWebPartPageUrl(pageUrl)
public SPList GetListFromWebPartPageUrl(
    string pageUrl
)

參數

  • pageUrl
    Type: System.String

    網頁組件頁面,例如/sites/sitecollection/subsite/default.aspx伺服器相對 URL。

傳回值

Type: Microsoft.SharePoint.SPList
指定的頁面上第一個網頁組件相關聯的清單。

Exceptions

Exception Condition
ArgumentNullException

pageUrl是 null 。

SPException

pageUrl不是有效的 URL。

-或-

指定的Web Parts page之第一個網頁組件不與清單產生關聯。

備註

這個方法會傳回與指定的Web Parts page之第一個網頁組件相關聯的清單。要傳回的Web Parts page本身相關聯的清單,請使用GetList方法。

Examples

下列範例會示範如何取得SPList物件,表示清單中第一個網頁組件,在預設的網頁的網站相關聯的主控台應用程式。

請注意此範例假設使用絕對 URL 的https://localhost/sites/sitecollection網站集合的存在,而且此網站集合具有名為subsite的網站。

Imports System
Imports Microsoft.SharePoint

Module ConsoleApp
   Sub Main()
      Using site As SPSite = New SPSite("https://localhost/sites/sitecollection")
         Using web As SPWeb = site.OpenWeb("subsite")

            Dim pageUrl As String = "/sites/sitecollection/subsite/default.aspx"
            Dim list As SPList = web.GetListFromWebPartPageUrl(pageUrl)
            Console.WriteLine("List URL: {0}", list.RootFolder.ServerRelativeUrl)

         End Using
      End Using
      Console.ReadLine()
   End Sub
End Module
using System;
using Microsoft.SharePoint;

namespace Test
{
   class ConsoleApp
   {
      static void Main(string[] args)
      {
         using (SPSite site = new SPSite("https://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();
      }
   }
}

請參閱

參照

SPWeb class

SPWeb members

Microsoft.SharePoint namespace