Application Pages Vs Site Content Pages Vs Custom aspx Pages Senario2

Scenario: 2 Application pages are those that are stored in the WSS/MOSS file system, usually found in the SharePoint root (12 hives) ADMIN and LAYOUTS folders. 47 A very simple way to extend the functionality of SharePoint is to create your own application page to enhance the administration of a web application, site collection, or site. In this example, we will create a simple page that writes out some information about the current web being administered. The first thing we will write is the page class; this will be used to provide the "code-behind" for the ASPX page that will be created later. 1. Open Visual Studio and create a new Class Library project, name this project AppPageExample 2. Rename the default Class1.cs file to AppPageCode.cs and allow it to rename the class (if this does not occur then change the actual class name manually) 3. Add references to Microsoft.SharePoint.dll and System.Web.dll to project 4. The SharePoint API exposes an inheritable class Microsoft.SharePoint.WebControls.LayoutsPageBase, this class includes common properties and methods that all standard application pages utilize. Change the AppPageExample class so that it inherits from the.


If you want to enrich your career and become a professional in SharePoint, then visit Tekslate - a global online training platform: "SharePoint Training"   This course will help you to achieve excellence in this domain.


Class using Microsoft.SharePoint.WebControls; namespace AppPageExample { public class AppPageCode : LayoutsPageBase { } } 5. Next we will move onto creating the ASPX file that will inherit from our page class created above. Add a new item to your project and select Text File. Name the file "AppPageExample.aspx". 6. Insert the code below into the newly created ASPX

Note: If using a different stongly named key file then the PublicKeyToken must be changed to reflect your PublicKeyToken <%@ Assembly Name="AppPageExample, Version=, Culture=neutral, PublicKeyToken=a191061ae245bc34" %> <%@ Page Language="C#" Inherits="AppPageExample.AppPageCode" MasterPageFile="~/_layouts/application.master" %>    <%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>    <asp:ContentID="Content1"ContentPlaceHolderID="PlaceHolderPageTitle"runat="server"> Application Page Example </asp:Content>   <asp:ContentID="Content2"ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"runat="server"> Application Page Example </asp:Content> <asp:ContentID="Content4"ContentPlaceHolderID="PlaceHolderPageDescription"runat="server"> An example of how to create an application page </asp:Content> <asp:ContentID="Content3"ContentPlaceHolderID="PlaceHolderMain"runat="server">   <asp:LiteralID="_litOutput"runat="server"/> </asp:Content> The asp:Literal control sitting in the main placeholder will be where we render the information about the site being viewed. 7. Switch back to the AppPageExample.cs file and create a field that maps to the control in the ASPX using System.Web.UI.WebControls; using Microsoft.SharePoint.WebControls; namespace AppPageExample { publicclass AppPageCode : LayoutsPageBase { protected Literal _litOutput; } }   8. Override the page class' OnLoad method and enter the code below protected override void OnLoad(System.EventArgs e) { StringBuilder oSb = new StringBuilder(); oSb.AppendFormat("Title: {0}", Web.Title); oSb.Append("<br/>"); oSb.AppendFormat("Name: {0}", Web.Name); oSb.Append("<br/>"); oSb.AppendFormat("Url: {0}", Web.Url); oSb.Append("<br/>"); oSb.AppendFormat("Description: {0}", Web.Description); oSb.Append("<br/>"); oSb.AppendFormat("ID: {0}", Web.ID); oSb.Append("<br/>"); oSb.AppendFormat("Language: {0}", Web.Language); oSb.Append("<br/>"); oSb.AppendFormat("MasterUrl: {0}", Web.MasterUrl); oSb.Append("<br/>"); oSb.AppendFormat("ServerRelativeUrl: {0}", Web.ServerRelativeUrl); _litOutput.Text = oSb.ToString(); } 9. The last step is to compile the assembly, add it into the GAC and then copy the ASPX file into the LAYOUTS folder in the SharePoint root directory (12/TEMPLATE/LAYOUTS). Navigate to the page using any web application url you have e.g. You should be presented with something similar to this: 48

For Indepth understanding of SharePoint click on: