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?