Friday, March 27, 2009

In-Line Script in SharePoint Page

You could add in-line script to a SharePoint page or Page template.

<asp:Content ID="main" runat="server"  ContentPlaceHolderID="PlaceHolderMain">
<% Response.Write("Hello Sanjay Sansanwal"); %>

You would able to access this page without error provided this page is ghosted(uncustomised) as WSS complies a ghosted page into an assembly DLL for processing.

But if you customise this page or open in SharePoint,  SharePoint safe mode don’t allow this and you would get error “Code blocks are not allowed in this file”.

You could force SharePoint to allow in-line scripts in customised pages by adding following to the web.config

  <SafeMode ... >
          AllowServerSideScript="true" />

Note: You should avoid doing this as it compromise SharePoint security. In-Line scripts are not allowed in customised pages so that unwanted user could not write malicious code to hack the system.