Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

public void SetDefaultPage()
{
    try
    {
        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;
            pubWeb.Update();
        }
    }
    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
    
Any Solutions to this problem? –  user13029 Nov 15 '12 at 15:16
add comment

1 Answer 1

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?

share|improve this answer
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.