Search This Blog

Thursday, July 22, 2010

[Tutorial] Enable Server Side Code in SharePoint Page Layout using SP Designer

If you use the Microsoft Office SharePoint Designer to add a new page to your site, you will see that it looks just like any other ASP.NET page. Open up your site with the SharePoint Designer, and then go to the Pages folder. Right-click the Pages folder and choose New / ASPX. That will generate a new ASP.NET page with the following default template:

1. Add following code-block to Web.Config, it should be locate in C:\Inetpub\wwwroot\wss\VirtualDirectories\<site>\Web.Config

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

2. Open the page layout that you going to add in server side code by using SharePoint designer.  It does how you do scripting like other way… and put your coding such as c# into it. like following :

<script runat="server">
protected void Page_Load(object sender, EventArgs e)

Response.Write(“Hello World !”);
}

</script>

3. Done. Happy Coding. ;-)

[reference] : http://blogs.msdn.com/b/kaevans/archive/2007/04/26/code-blocks-are-not-allowed-in-this-file-using-server-side-code-with-sharepoint.aspx

No comments:

Post a Comment