Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6215583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:05:02+00:00 2026-05-24T07:05:02+00:00

I ran into this error recently when trying to get all the page layouts

  • 0

I ran into this error recently when trying to get all the page layouts in a publishing site (Microsoft.SharePoint.Publishing.PublishingWeb) from a custom layouts page in a subsite. The code worked on a VM server using a site created from the Enterprise Wiki site template. But when running on the development server the code encountered various exceptions.

Attempting to get around the error, I coded the class three different ways. All three worked in the VM, but all three threw an exception when used in the development server. Example:

private PageLayout FindPageLayout(PublishingWeb pubWeb, string examplePage)
        {
            /* The error occurs in this method */
            if (pubWeb == null)
                throw new ArgumentException("The pubWeb argument cannot be null.");
            PublishingSite pubSiteCollection = new PublishingSite(pubWeb.Web.Site);
            string pageLayoutName = "EnterpriseWiki.aspx"; // for testing purposes
            PageLayout layout = null;

            /* Option 1: Get page layout from collection with name of layout used as index
             * Result: System.NullReferenceException from GetPageLayouts()
             */

            layout = pubSiteCollection.PageLayouts["/_catalogs/masterpage/"+pageLayoutName];

            /* Option 2: Bring up an existing publishing page, then find the layout of that page using the Layout property
             * Result: Incorrect function COM exception
             */

            SPListItem listItem = pubWeb.Web.GetListItem(examplePage);
            PublishingPage item = PublishingPage.GetPublishingPage(listItem);
            layout = item.Layout;

            /* Option 3: Call "GetPageLayouts" and iterate through the results looking for a layout of a particular name
             * Result: System.NullReferenceException thrown from Microsoft.SharePoint.Publishing.PublishingSite.GetPageLayouts()
             */

            PageLayoutCollection layouts = pubSiteCollection.GetPageLayouts(true);
            for(int i = 0; i < layouts.Count; i++)
            {
                // String Comparison based on the Page Layout Name
                if (layouts[i].Name.Equals(pageLayoutName, StringComparison.InvariantCultureIgnoreCase))
                    layout = layouts[i];
            }

            return layout;
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:05:03+00:00Added an answer on May 24, 2026 at 7:05 am

    Here was the solution I found after a week or so:

    Make sure that when you are getting your “PublishingWeb” object by calling that PublishingWeb.GetPublishingWeb(SPWeb) method that you are passing into it an SPWeb objec that has been fully retrieved. More specifically, I would make sure to call SPSite.OpenWeb on any website, as follows:

     using (SPSite site = new SPSite(folder.ParentWeb.Url))
                {
                    SPWeb web = site.OpenWeb();
                    PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
                    /* work with PublishingWeb here ... */
                    web.Close();
                 }
    

    Once I made this simple change, all the errors mentioned in the question were cleared up, no matter in what context I called “GetPageLayouts” or “GetAvailablePageLayouts”. The method documentation says this, and it really means it:

    Use this method in order to access PublishingWeb behavior for an
    instance of a SPWeb class that has already been retrieved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I ran into this error in my web application: java.lang.OutOfMemoryError: PermGen space It's
trying to integrate hibernate and spring ,I ran into this error SEVERE: Context initialization
I ran into this error when building my code with CLANG: In file included
I ran into unbound method error in python with this code: import random class
I first ran into this when trying to determine the relative performance of two
I recently ran into an odd issue where I'd get a const_iterator instead of
I ran into this error when I try to evaluate the last line below:
I am trying to organize my program into functions and have ran into this,
Occasionally, on a ASP (classic) site users will get this error: [DBNETLIB][ConnectionRead (recv()).]General network
While writing the touchesBegan handler for my view I ran into this interesting error.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.