Sunday, September 7, 2008

Creating Custom Application Page

Scenario:
You want to write a Custom Application Page for some additional configurations for all of your sites.

Myconfig.ASPX(12/TEMPLATE/Layouts/Client/):


<%@ Assembly Name="Microsoft.SharePoint,[rest of 3-part assembly infomation]"%>
<%@ 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" >
'Hello World' of Application Page
</asp:Content>
Usage:
You can access to the page from any web i.e.
 http://localhost/_layouts/client/myconfig.aspx
or you can also write a CustomAction to access the URL

0 comments: