0

I created a new document library instance programmatically. I added the contenttype "Enterprise Wiki Page" to this library. I added also a module where I add a new pagelayout. This pagelayout is assiciated to the contenttype "Enterprise Wiki Page". When I deploy and try to create a new page with this pagelayout I got an exception:

Application error when access /_layouts/15/CreatePage.aspx, Error=Value does not fall within the expected range.  
 at Microsoft.SharePoint.Utilities.SPUtility.CreateParentFoldersForFile(SPList list, String url, Boolean createAsListItem)    
 at Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePagePage.NewPageItemSave(String pageName, PageLayout pageLayout, String folderUrl, Boolean redirect)    
 at Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePagePage.CreateStandardPage(String pageName)    
 at Microsoft.SharePoint.Publishing.Internal.CodeBehind.CreatePagePage.ButtonCreatePage_Click(Object sender, EventArgs e)    
 at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)    
 at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

This is the module of the pagelayout:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Name="PageLayouts" Url="_catalogs/masterpage">
    <File Path="PageLayouts\DistWikiPage.aspx" Url="DistWikiPage.aspx" Type="GhostableInLibrary" ReplaceContent="TRUE" Level="Published">
      <Property Name="Title" Value="Dist Wiki Page" />
      <Property Name="MasterPageDescription" Value="Dist Wiki Pagina Layout" />
      <Property Name="ContentType" Value="$Resources:cmscore,contenttype_pagelayout_name;" />
      <Property Name="PublishingPreviewImage" Value="~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/WelcomeSplash.png, ~SiteCollection/_catalogs/masterpage/$Resources:core,Culture;/Preview Images/WelcomeSplash.png" />
      <Property Name="PublishingAssociatedContentType" Value=";#Ondernemingswikipagina;#0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF39004C1F8B46085B4D22B1CDC3DE08CFFB9C;#" />
    </File>
  </Module>
</Elements>

This is the pagelayout aspx:

<%@ Page language="C#"   Inherits="Microsoft.SharePoint.Publishing.PublishingLayoutPage,Microsoft.SharePoint.Publishing,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full" meta:progid="SharePoint.WebPartPage.Document" %>
<%@ Register Tagprefix="SharePointWebControls" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> <%@ Register Tagprefix="PublishingNavigation" Namespace="Microsoft.SharePoint.Publishing.Navigation" Assembly="Microsoft.SharePoint.Publishing, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<asp:Content ContentPlaceholderID="PlaceHolderPageTitle" runat="server">
    <SharePointWebControls:FieldValue id="PageTitle" FieldName="Title" runat="server"/>
</asp:Content>
<asp:Content ContentPlaceholderID="PlaceHolderMain" runat="server">
</asp:Content>
  • I'm wondeting how you expect the new page to go to your custom doc lib instead of "Pages"? – Evariste Sep 2 '15 at 16:35
  • thats not the issue. I can see the contenttype and pagelayout in my custom document library. So thats ok. I add the contenttype to my custom document library programmatically. – Ola Sep 2 '15 at 16:49
  • That may be related to the issue actually, since your page goes "by default" into "Pages". And the error looks like it cannot find that doc lib, or cannot create a folder in it. + it may give some context or give other users some ideas. – Evariste Sep 2 '15 at 17:18
  • I do not create a new page from the right top corner. I create a new page from the custom document library from the top left corner. The drop down where you can see all the content types from the custom document library. – Ola Sep 3 '15 at 6:51
  • Please, see my answer below... – Evariste Sep 3 '15 at 9:46
1

Looking at the call stack, and with the help of ILSpy to inspect the SharePoint code, we can see that:

  1. Your code fails at CreateParentFoldersForFile
  2. CreateParentFoldersForFile is called by CreatePagePage.NewPageItemSave.
  3. The only call to CreateParentFoldersForFile from CreatePagePage.NewPageItemSave is as follow:

    SPUtility.CreateParentFoldersForFile(currentPublishingWeb.PagesList, url, false);

As you can see, it tries to connect to the native Pages doc lib of your publishing site. It's probably where it fails if there's no Pages doc lib... or if the URL you pass does not match the Pages doc lib... That's why I asked you how you create a publishing page in a custom doc lib... I'm not sure you can achieve this...

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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