SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When creating publishing web, we use this method for setting default page:

public void SetDefaultPage()
        if (PublishingWeb.IsPublishingWeb(_courseWeb))
            PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(_courseWeb);

            // get publishing page
            string url = _courseWeb.ServerRelativeUrl;
            //url = url.Substring(url.LastIndexOf("/"));
            string pageUrl = string.Format("{0}/{1}/{2}", url, pubWeb.PagesListName, START_PAGE_NAME);
            var pubPage = pubWeb.GetPublishingPage(pageUrl);
            pubWeb.DefaultPage = pubPage.ListItem.File;
    catch (ArgumentException exception)
        LoggingService.LogError(LogCategory.ARCHIVE, "SetDefaultPage failed ! (ArgumentException)");
        LoggingService.LogError(LogCategory.ARCHIVE, exception.Message);
        LoggingService.LogError(LogCategory.ARCHIVE, exception.StackTrace);

This method works as expected when we are creating web, turning on publishing features and then calling this method.

But when we use SPExport and SPImport mechanisms and then try to call this method, it throws ArgumentException on this line: var pubPage = pubWeb.GetPublishingPage(pageUrl);

We thought that there file might not exists, but it is present. We also tried getting Pages list manually, and then getting list item from it, but this code snippet:

var pagesList = pubWeb.Lists[pubWeb.PagesListName]

throws error that list doesnt exist. What is more interesting, calling this method is successful from time to time, but there is no rule when it works and when not. I wonder what might be the cause. Web is properly recognized as publishing web, but it fails to obtain publishing pages list or publishing page (when passing URL), which in fact exist, because when accessing web manually, one can see proper contents of Pages library. Maybe there is some kind of delay on export/import? Any ideas what could be the cause and how to solve this issue?

share|improve this question
Have you tried to use PublishingWeb.PagesList? – Per Jakobsen Oct 10 '12 at 16:22
Perhaps it is the way pageurl is constructed. Do you have a development environment where you can attach a debugger to inspect the value in that variable? – James Mann Oct 11 '12 at 12:46
Any Solutions to this problem? – user13029 Nov 15 '12 at 15:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.