This topic has not yet been rated - Rate this topic

How to: Retrieve the URL of a Pages library

SharePoint 2013

Published: September 10, 2013

Learn how to retrieve the URL for the pages list for a publishing web in a site collection that differs from the current context.

When developing custom applications for publishing sites, you may notice that the PublishingWeb object model does not expose a way to retrieve the URL for the Pages list of a publishing web in a site collection that differs from the current context. Although the PublishingWeb class wraps the SPWeb class for instances that have the publishing feature activated, the class is not intended to be used to instantiate SPWeb objects outside of the current context.

If you need to retrieve the URL for the Pages list for a different web application, you can query the Properties property. Since the PublishingWeb object is the SPWeb object of a publishing site, you can query the Properties property and write its contents to a console application. If the entry Key = vti_pageslistname, Value = {the URL to the Pages library} is returned in the console, {the URL to the Pages library} is the Pages list URL.

Table 1. Core concepts for retrieving the URL of a Pages library

Article title

Description

Pages Library

A document library that contains all the content pages for a publishing site.

SPWeb

Represents a SharePoint Foundation website.

Properties

Gets a SPPropertyBag object with metadata for the current website.

SPPropertyBag

Stores arbitrary key and value pairs that contain custom property settings.

PublishingWeb

Provides publishing behavior for an instance of SPWeb that supports publishing.

This example console application accesses the Properties property, iterates through the collection, and writes each key/value pair to the console.

To query the SPWeb.Properties property for the URL to the Pages list

  1. Write the console application.

  2. View the output in the console.

The application queries the SPPropertyBag object, iterates through its dictionary entries, and writes those entries to the console.

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();
        }
    }
}

The output that this application prints to the console varies from website to website, but it might look like the following:

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}

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.