Sunday, March 1, 2009

How to create Custom Aspx Page in Sharepoint

For creating custom aspx page in Sharepoint follow the steps

  1. First, create a Class Library project in vs 2005/2008.
  2. Add Microsoft.SharePoint dll reference
  3. Create a file called HelloWorld.aspx or or you can create a sepeate code behind .cs file but add code into you
  4. Sign a strong key and build the project.
  5. Add the assembly into GAC
  6. Create a folder for example say 'test' and then Copy the HelloWorld.aspx to C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\Test
  7. Now run the page as http://portal/_layouts/Test/HelloWorld.aspx
<%@ Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c"%>
<%@ 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 = SPContext.Current.Web;
    SPWeb site = this.Web;
    lblSiteTitle.Text = site.Title;
    lblSiteID.Text = site.ID.ToString().ToUpper();
  }
</script>

<asp:Content ID="Main" contentplaceholderid="PlaceHolderMain" runat="server">
  <table border="1" cellpadding="4" cellspacing="0" style="font-size:12">
    <tr>
      <td>Site Title:</td>
      <td><asp:Label ID="lblSiteTitle" runat="server" /></td>
    </tr>
    <tr>
      <td>Site ID:</td>
      <td><asp:Label ID="lblSiteID" runat="server" /></td>
    </tr>
  </table>
</asp:Content>

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

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

0 comments:

Post a Comment