检索页面库的 URL

了解如何在与当前上下文不同的网站集中为发布网站检索页面列表的 URL。

检索页面列表 URL 的核心概念

开发用于发布网站的自定义应用程序时,你可能会注意到 PublishingWeb 对象模型不公开检索与当前上下文不同的网站集中发布网站的页面列表的 URL 的方法。 尽管 PublishingWeb 类为已激活发布功能的实例封装 SPWeb 类,但是该类并用于实例化当前上下文之外的 SPWeb 对象。

如果需要检索其他 Web 应用程序的 Pages 列表的 URL,可以查询 Properties 属性。 因为 PublishingWeb 对象是一个发布网站的 SPWeb 对象,您可以查询 Properties 属性,然后将其内容写入控制台应用程序。 如果在控制台中返回条目 Key = vti_pageslistname, Value = {the URL to the Pages library}则 {页面库的 URL} 是页面列表 URL。

表 1. 检索页面库 URL 的核心概念

文章标题 说明
页面库
文档库包含发布网站的所有内容页面
SPWeb
代表一个 SharePoint Foundation 网站。
Properties
获取包含当前网站的元数据的 SPPropertyBag 对象。
SPPropertyBag
存储包含自定义属性设置的任意键和值对。
PublishingWeb
为支持发布功能的 SPWeb 实例提供发布行为。

在与当前上下文不同的网站集中为发布网站检索页面列表的 URL

此示例控制台应用程序访问 Properties 属性,循环访问集合,并将每个键/值对写入控制台。

查询页面列表 URL 的 SPWeb.Properties 属性

  1. 编写控制台应用程序。

  2. 查看控制台中的输出。

示例: 查询页面列表 URL 的 SPWeb.Properties 属性

应用程序查询 SPPropertyBag 对象,循环访问其字典条目,并将这些条目写入控制台。


using System;
using System.Collections;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    SPPropertyBag props = web.Properties;
                    foreach (DictionaryEntry de in props)
                    {
                        Console.WriteLine("Key = {0}, Value = {1}", de.Key, de.Value);
                    }
                }
            }
            Console.ReadLine();
        }
    }
}

此应用程序打印至控制台的输出会因网站的不同而异,但它外观可能类似于以下内容:


Key = vti_associatemembergroup, Value = 5
Key = vti_extenderversion, Value = 14.0.0.4016
Key = vti_associatevisitorgroup, Value = 4
Key = vti_associategroups, Value = 5;4;3
Key = vti_createdassociategroups, Value = 3;4;5
Key = vti_siteusagetotalbandwidth, Value = 547
Key = vti_siteusagetotalvisits, Value = 9
Key = vti_associateownergroup, Value = 3
Key = vti_defaultlanguage, Value = en-us
Key = vti_pageslistname, Value = {the URL to the Pages list}

另请参阅