Spiga

Application Pages

The Awesome power of Application Pages

A useful link http://msdn.microsoft.com/en-us/library/bb418732.aspx

In VS.Net 2005 on your MOSS Server Development Environment create an empty Sharepoint Project. (I called mine MOSS.Web.Application)
Add a reference to Microsoft.SharePoint (Windows® SharePoint® Services) v2.0.50727
In my environment its at C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll

(If you can't work out which one to choose add a webpart to the solution then delete the Webpart bits that were just added)


Add a directory named Templates to the project root
Add a directory named LAYOUTS to the Templates Directory you just made
Add a directory named {Your Application Page Directory} to LAYOUTS (I made one called Basic)
Under {Your Application Page Directory} add a file called default.aspx with this code in it.




<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@ Assembly Name="MOSS.Web.Application, Version=1.0.0.0, Culture=neutral, PublicKeyToken={PUBLIC KEY TOKEN}"%>

<%@ Page Language="C#" MasterPageFile="~/_layouts/application.master"
Inherits="MOSS.Web.Application.Basic.Default" %>



<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>


Under {Your Application Page Directory} add a file called default.aspx.cs with this code in it.


using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace MOSS.Web.Application.Basic
{

[CLSCompliant(false)]
public class Default : LayoutsPageBase
{

// add control fields to match controls tags on .aspx page
protected Label lblSiteTitle;
protected Label lblSiteID;

protected override void OnLoad(EventArgs e)
{

// get current site and web
SPSite siteCollection = this.Site;
SPWeb site = this.Web;

// program against controls on .aspx page
lblSiteTitle.Text = site.Title;
lblSiteID.Text = site.ID.ToString().ToUpper();
}
}
}


Go to your project's WSP View and open manifest.xml making sure this code is in there




<?xml version="1.0" encoding="utf-8"?>
<Solution SolutionId="ce340c94-3b75-4abd-9a2d-537b8db6ada5" xmlns="http://schemas.microsoft.com/sharepoint/">
<Assemblies>
<Assembly Location="MOSS.Web.Application.dll" DeploymentTarget="GlobalAssemblyCache" />
</Assemblies>
<TemplateFiles>
<TemplateFile Location="LAYOUTS\Basic\default.aspx" />
<TemplateFile Location="LAYOUTS\Basic\Default.aspx.cs" />
<TemplateFile Location="LAYOUTS\Basic\Web.config" />
</TemplateFiles>
</Solution>


In the Project's Properties on the Debug Page put the url to the MOSS Site you wish to deploy to.

Once you have done that go to the Build menu and Deploy your Project

You will find it at {Your Sharepoint url}/_layouts/{Folder}/{Page}

0 comments: