Apr
3
2008

Code blocks are not allowed in this file - SharePoint error with custom page layout

Yes, I do have C# code in custom page layout. And you probably thinking it is just another post about putting "<PageParserPath />" tag inside web.config.

But the answer is No. I managed to pin down the problem without having <PageParserPath /> tag. Well.. at least in my case.

Problem -

I got this error when I was creating a new publishing page, base on the custom page layout I have deployed to SharePoint site.

James Tsai .Net Blog - C# ASP.NET SharePoint VSTO - Page Layout code block error

Solution

The reason I know <PageParserParth /> is not the answer to this problem is that, only two out of seven page layouts I deployed having this issue.

So I opened those "broken" page layouts from the site in SharePoint designer and found following code got injected to the bottom of my custom page layouts


<html xmlns:mso="urn:schemas-microsoft-com:office:office"
xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"><head> <META name="WebPartPageExpansion" content="full"> <!--[if gte mso 9]><xml> <mso:CustomDocumentProperties> <mso:PublishingPreviewImage msdt:dt="string"></mso:PublishingPreviewImage> <mso:ContentType msdt:dt="string">Page Layout</mso:ContentType> <mso:MasterPageDescription msdt:dt="string"></mso:MasterPageDescription> <mso:PublishingAssociatedVariations msdt:dt="string">
</mso:PublishingAssociatedVariations> <mso:PublishingHidden msdt:dt="string">0</mso:PublishingHidden> <mso:PublishingAssociatedContentType msdt:dt="string">
;#Agenda item;#0x010100C568DB52D...;#</mso:PublishingAssociatedContentType> </mso:CustomDocumentProperties> </xml><![endif]--> <title>Dummy Content Type</title></head>

I couldn't figure out how this got into my page layouts . But I am sure that SharePoint treated those "broken" page layouts differently as to other working page layouts.

I compared them side by side, read about PlaceHolderPageTitle is the root of all evil  post. I found in my broken page layouts they all got lower case <asp:content /> tag for PlaceHolderPageTitle place holder. So I changed <asp:content /> to <asp:Content />, and it fixed the problem!


<asp:Content contentplaceholderid="PlaceHolderPageTitle" runat="server"> <SharePointWebControls:FieldValue id="PageTitle"
FieldName="Title" runat="server"/> </asp:Content>

Unlike Waldek's situation in the his post, I do have PlaceHolderPageTitle place holder in my page layouts. So this place holder is case sensitive? (because all my other place holders still use lower case <asp:content /> tag. )

blog comments powered by Disqus