Connect.Collaborate.SharePoint

How to run inline code in SharePoint aspx pages

This question has been cropping up quite often so hopefully this post will make it easier to find in the search engines.

Say you want to add some code like this into a SharePoint Web Part Page

<%
         Server.Transfer(@"/_layouts/listfeed.aspx?List={D5813C18-934F-4FD6-9068-5CDD59CE56BA}");
%>

If you try and view the page you will get an error saying "An error occurred during the processing of xxx.aspx. Code blocks are not allowed in this file".To enable this you need to modify the web.config file for your SharePoint Site Collection.
To enable code blocks in single files, add the following section...

<PageParserPaths>

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

</PageParserPaths>

 To specify all files in a path (Document Library) the path statement can include a wild card (*) in which case you can also add IncludeSubFolders="true" parameter to the PageParserPath to allow inline code for any page.

Posted by Ian Morrish on Monday, 15 Jan 2007 08:10 | 2 Comments

Links to this post

Trackback from Blog on 12 Apr 2008 08:58

Name

Url

Email

Comments

CAPTCHA Image Validation