Export (0) Print
Expand All
Expand Minimize
24 out of 55 rated this helpful - Rate this topic

Creating an Application Page in Windows SharePoint Services 3.0

Windows SharePoint Services 3
Visual How To

Applies to:  Microsoft Windows SharePoint Services 3.0, Microsoft Office SharePoint Server 2007, Microsoft Visual Studio 2005

Ted Pattison, Ted Pattison Group

May 2007

Overview

You can create custom application pages to add user interface components to a custom solution based on Microsoft Windows SharePoint Services 3.0. Unlike site pages (for example, default.aspx), a custom application page is deployed once per Web server and cannot be customized on a site-by-site basis. Application pages are based in the virtual _layouts directory. In addition, they are compiled into a single assembly DLL. They are also used across all sites within a server farm. For these reasons, they perform better than site pages. With application pages, you can also add inline code. With site pages, you cannot add inline code.

Code It

Typically, you link custom application pages to application.master, the master page file that is used by the default application pages in Windows SharePoint Services. You should also write application pages to inherit from a base class defined inside the Microsoft.SharePoint assembly named LayoutsPageBase. The following example provides the basic layout for a custom application page.

<%@ Assembly Name="Microsoft.SharePoint, [full 4-part assembly name]"%> 
<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master" 
         Inherits="Microsoft.SharePoint.WebControls.LayoutsPageBase" %>

<%@ Import Namespace="Microsoft.SharePoint" %>

<script runat="server">
  protected override void OnLoad(EventArgs e) {
    SPWeb site = this.Web;
    lblSiteTitle.Text = site.Title;
    lblSiteID.Text = site.ID.ToString().ToUpper();
  }
</script>

<asp:Content ID="Main" runat="server"
             contentplaceholderid="PlaceHolderMain" >
  Site Title: <asp:Label ID="lblSiteTitle" runat="server" />
  <br/>
  Site ID: <asp:Label ID="lblSiteID" runat="server" />
</asp:Content>

<asp:Content ID="PageTitle" runat="server" 
             contentplaceholderid="PlaceHolderPageTitle" >
   Hello World
</asp:Content>

<asp:Content ID="PageTitleInTitleArea" runat="server"
             contentplaceholderid="PlaceHolderPageTitleInTitleArea" >
   The Quintessential 'Hello World' of Application Page
</asp:Content>

Deployment

Note that although you can deploy your application pages directly inside the \LAYOUTS directory, doing so can create file name conflicts between your application pages and those application pages that are created by Microsoft and other companies. It is a best practice to deploy your application pages inside a company-specific or project-specific directory that is nested with the \LAYOUTS directory. For example, you can deploy application pages within a company-specific directory located at the path \LAYOUTS\Litware.

Read It

You usually create custom application pages with a link to the application.master file. The custom application page demonstrated in this How-To sample adds three Content tags to add HTML content to the resulting page. In particular, this page replaces three placeholders that are defined inside application.master: PlaceHolderMain, PlaceHolderPageTitle and PlaceHolderPageTitleInTitleArea. However, these are only three of the many different placeholders that you can choose to replace.

Also note that an application page can have a script block at the top with code that programs against the object model. When you program a similar page within Microsoft Visual Studio 2005, you can benefit from conveniences such as color-coding and Microsoft IntelliSense. However, you must add the correct @Assembly directive to the top of the page to reference the Microsoft.SharePoint assembly.

Application pages are useful because they provide quick and easy access to the Windows SharePoint Services object model. After you create an application page and provide an overridden implementation of the OnLoad method, you can obtain entry points into the Windows SharePoint Services object model in a site-specific context by using the following code.

SPSite siteCollection = SPContext.Current.Site;
SPWeb site = SPContext.Current.Web;

The ability to obtain site-relative context makes writing application pages far more powerful. An application page can function differently depending on which site you go through to access it. When you navigate to an application through the context of one site, it typically appears and functions differently than when you navigate to it through the context of another site.

See It

Create Custom Application Page

Watch the Video

Video Length: 00:04:57

File Size: 13.2 MB WMV

Explore It
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.