• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

Application Pages Vs Site Content Pages Vs Custom aspx Pages

Scenario: 2

Application pages are those that are stored in the WSS/MOSS file system, usually found in the SharePoint root (12 hive) 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 the 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

LayoutsPageBase 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

Learn the core features of SharePoint and become master with our expertise tutorials.

Note: If using a different stongly named key file then the PublicKeyToken must be changed to reflect your

PublicKeyToken

<%@ Assembly Name=”AppPageExample, Version=1.0.0.0, 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=12.0.0.0, 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. http://your.site.url/_layouts/AppPageExample.aspx. You should be presented with something similar to this:
48

For Indepth understanding of SharePoint click on

 

Summary
Review Date
Reviewed Item
Application Pages Vs Site Content Pages Vs Custom aspx Pages Senario2
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Application Pages Vs Site Content Pages Vs Custom aspx Pages Senario2"

    Leave a Message

    Your email address will not be published. Required fields are marked *

    Site Disclaimer, Copyright © 2016 - All Rights Reserved.

    Support


    Please leave a message and we'll get back to you soon.

    I agree to be contacted via e-mail.