SPWeb.GetListFromWebPartPageUrl 方法

Gets the list that is associated with the first Web Part on the specified Web 部件页.

命名空间:  Microsoft.SharePoint
程序集:  Microsoft.SharePoint(位于 Microsoft.SharePoint.dll 中)

语法

声明
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
    类型:System.String

    The server-relative URL of a Web Part page, such as /sites/sitecollection/subsite/default.aspx.

返回值

类型:Microsoft.SharePoint.SPList
The list that is associated with the first Web Part on the specified page.

异常

异常 条件
ArgumentNullException

pageUrl is null .

SPException

pageUrlis not a valid URL.

-or-

The first Web Part on the specified Web 部件页 is not associated with lists.

备注

This method returns the list that is associated with the first Web Part on the specified Web 部件页. To return the list that is associated with the Web 部件页 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 https://localhost/sites/sitecollection and that this site collection has a website named 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 类

SPWeb 成员

Microsoft.SharePoint 命名空间