Site Pages & PageParserPath

on Thursday, February 18, 2010

Hi,

You can have two kind of Site Pages.
1. Uncustomized(Ghosted) which resides in the file system.
2. Customized which are stored in the Content Database.

UnCustomized Pages can be created using visual studio and can be deployed using features.

Sample ASPX Page

<%@ Page Language="C#" MasterPageFile="~masterurl/default.master" meta:progid="SharePoint.WebPartPage.Document" Inherits="CustomizedPageLibrary.PageTemplate,CustomizedPageLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=fa90fd1d7c28abf3" %>

<asp:Content ID="Content2" runat="server" ContentPlaceHolderID="PlaceHolderMain">
<asp:Label ID="lblHello" runat="server" BackColor=Red></asp:Label>
<asp:Button ID="btnHello" runat="server" OnClick="btnHello_Click"/>
</asp:Content>
 
 Code Behind

Create a class library project and add System.Web and Microsoft.SharePoint.Publishing dll references.
Then add following class and strong name the dll.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Publishing;
using System.Web.UI.WebControls;

namespace CustomizedPageLibrary
{
    public class PageTemplate : PublishingLayoutPage
    {
        protected System.Web.UI.WebControls.Label lblHello;
        protected Button btnHello;
        void Page_Load(object sender, EventArgs e)
        {
            lblHello.Text = "Hello1";
        }
        protected void btnHello_Click(object sender, EventArgs e)
        {
            lblHello.Text = "Hello" + DateTime.Now.ToString();
        }
    }

}


Install the assembly in the GAC


To deploy the site page into the site's Shared Documents library
feature.xml

<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
         Id="597D8309-C964-48ef-8D24-D5C60C94A832"
         Title="MSDN Uncustomized Page Feature"
         Scope="Web">
  <ElementManifests>
    <ElementManifest Location="elements.xml"/>
    <ElementFile Location="PageTemplate.aspx" />
  </ElementManifests>
</Feature>



elements.xml
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <Module Url="Shared Documents">
    <File Url="PageTemplate.aspx" Name="SamplePage.aspx" Type="GhostableInLibrary" />
  </Module>
</Elements>


Note: If you don't want to deploy it to Some doclib then you can use Type="Ghostable" as well.


Customized Pages


The aspx file above can be uploaded into some document library and the page is ready to be used if you don't have any inline code or any server side code to execute. If you want to execute some serverside code then you need to add following entry in the web.config in <PageParserPaths> element. Any page in the content database that needs to execute server side code needs to have the PareParserPath entry in web.config file.

<PageParserPaths>
        <PageParserPath VirtualPath="/Shared Documents/*" CompilationMode="Always"
AllowServerSideScript="true" IncludeSubFolders="true"/>
</PageParserPaths>

0 comments: