Hammendorp.net

Blogging about SharePoint and other development
If you want to retrieve the url of the PublishingPage , it is better to use Page.Uri.AbsoluteUri instead of Page.Url. Because Page.Url gives you the server relative url, this can be the result you don't want. With Page.Uri.AbsoluteUri, yuo are always safe.


When you create an ASPX page in Sharepoint (for example in Sharepoint Designer), you might get the error 'Code-Blocks are not allowed in this file' when you run the page. This is because SharePoint disables the ability to create server-side script by default, you have to turn it on.

You can do this by modifying the web.config; in the configuration/SharePoint/PageParserPaths configuration section:

<PageParserPaths>
   <PageParserPath VirtualPath="/pages/mypage.aspx" CompilationMode="Always" AllowServerSideScript="true" />
</PageParserPaths>

After saving the web.config and a reload of your page, the error should be gone.



So this looks easy, but I have search a lot to get to this answer.

If you want to get the value from a specific field in a PublishingPage item, I used the next construction:


SPWeb rootWeb = SPContext.Current.Web.Site.OpenWeb(itemPath);
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(rootWeb);
pages = pweb.GetPublishingPages();

foreach (PublishingPage page in pages)
{
   string fieldValue = page.ListItem["xxx"] as string;
   Response.Write("Field xxx has value: " + fieldValue);
}



Bas Hammendorp

I am Bas Hammendorp, working as SharePoint developer at PGGM Zeist

Month List

Sign in