Application pages reside in the file system. These are different from web part pages, which are stored in the database. Unlike web part pages, application pages are not customizable. Application pages reside in the Layouts folder under the <14 Hive>Template folder. An application page is really like the usual ASP.NET page that inherits from the Microsoft.SharePoint.WebControls.LayoutsPageBase
class.
Try It Yourself: Write a Simple Application Page
1. Create a new empty SharePoint project and name it DemoApplicationPage. Add a new item of type Application Page named as SiteInfo.aspx. A new ASPX page and code behind file gets added to the project under the LayoutsDemoApplicationPage folder, as shown in Figure 6.8.
2. Edit the SiteInfo.aspx and update as follows:
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register
Tagprefix="SharePoint"
Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register
Tagprefix="Utilities"
Namespace="Microsoft.SharePoint.Utilities"
Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register
Tagprefix="asp"
Namespace="System.Web.UI"
Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly
Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeBehind="SiteInfo.aspx.cs"
Inherits="DemoApplicationPage.Layouts.DemoApplicationPage.SiteInfo"
DynamicMasterPageFile="~masterurl/default.master" %>
<asp:Content
ID="PageHead"
ContentPlaceHolderID="PlaceHolderAdditionalPageHead"
runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
<asp:Literal runat="server" ID="LiteralInfo"></asp:Literal>
</asp:Content>
<asp:Content
ID="PageTitle"
ContentPlaceHolderID="PlaceHolderPageTitle"
runat="server">
Site Info
</asp:Content>
<asp:Content
ID="PageTitleInTitleArea"
ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
runat="server" >
Site Info
</asp:Content>
3. Edit the code behind as follows:.
using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Text;
namespace DemoApplicationPage.Layouts.DemoApplicationPage
{
public partial class SiteInfo : LayoutsPageBase
{
protected void Page_Load(object sender, EventArgs e)
{
SPWeb web = SPContext.Current.Web;
StringBuilder html = new StringBuilder();
html.Append("Some random info. about the current site <BR/>");
html.Append("<OL>");
html.AppendFormat("User Name: {0} <BR/>",
web.CurrentUser.Name);
html.AppendFormat("Url : {0} <BR/>", web.Url);
html.AppendFormat("User Name: {0} <BR/>",
web.CurrentUser.Name);
html.AppendFormat("Site Master Url: {0} <BR/>",
web.CustomMasterUrl);
html.AppendFormat("System Master Url: {0} <BR/>",
web.MasterUrl);
html.Append("</OL>");
this.LiteralInfo.Text = html.ToString();
}
}
}
4. Build and deploy the solution. Browse to the application page by going to the URL http://localhost/_layouts/DemoApplicationPage/SiteInfo.aspx. You see the screen shown in Figure 6.9.
Application pages are really simple. They are built mostly for administration tasks and you will find that most links in the Site Settings page point to application pages.