StiePages with Code Behind(Feature,install.bat)
The aspx pages : Need to convert the third brackets to angular brackets
[%@ Page Language="C#" MasterPageFile="~masterurl/default.master" Debug="true" Inherits="TestSitePage,SitePages,Version=1.0.0.0,Culture=neutral,PublicKeyToken=5241345d6ad43482" meta:progid="SharePoint.WebPartPages.Document" %]
[asp:content id="C1" runat="server" contentplaceholderid="PlaceHolderPageTitle"]
Test Site Page [/asp:content]
[asp:content id="C2" runat="server" contentplaceholderid="PlaceHolderMain"]
[asp:label id="Label1" runat="server" text="Label"][/asp:label]
[asp:button id="Button1" runat="server" text="Button"]
[/asp:button][/asp:content]
[asp:button id="Button1" runat="server" text="Button"] [/asp:button]
Now in the C# page...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Utilities;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using System.Web.UI;
public partial class SitePages: Page
{
protected Label Label1;
protected Button Button1;
//protected override void OnPreInit(EventArgs e)
//{
// base.OnPreInit(e);
// //this.MasterPageFile = SPContext.Current.Web.ServerRelativeUrl + "/_catalogs/masterpage/default.master";
// this.MasterPageFile = SPContext.Current.Web.MasterUrl;
//}
protected override void OnInit(EventArgs e)
{
//base.OnInit(e);
Button1.Click += new EventHandler(Button1_Click);
}
protected void Button1_Click(object sender, EventArgs e)
{
Label1.Text = Label1.Text.Trim() + DateTime.Now.ToString();
}
//protected void Page_Load(object sender, EventArgs e)
//{ Label1.Text = "Hello World Code Behind";
//}
}
-----
Feature.xml
[feature id="5A8158F4-2AAD-4608-A03F-F33A7FDA3945" title="LA Site Pages" description="These are the LA Site Pages" xmlns="http://schemas.microsoft.com/sharepoint/" scope="Web" version="1.0.0.0" hidden="FALSE"]
[elementmanifests]
[elementmanifest location="Elements.xml"]
[elementfile location="TestPage1.aspx"]
[elementfile location="StartPage.aspx"]
[/elementfile][/elementfile][/elementmanifest][/elementmanifests]
[/feature]
---
Elements.xml
[elements xmlns="http://schemas.microsoft.com/sharepoint/"]
[module url="Sample"]
[file url="TestPage1.aspx" name="TestPage1.aspx" type="Ghostable"]
[/file]
[/module]
[module url=" Sample"]
[file url="StartPage.aspx" name="StartPage.aspx" type="Ghostable"]
[/file]
[/module]
[customaction id="757CEE41-D25E-47f3-A088-A9ED11C896F6" title="LA Test Pages" description="Shows the SP Site Test Pages" location="Microsoft.SharePoint.StandardMenu" groupid="SiteActions" sequence="99"]
[urlaction url="~site/Sample/TestPage1.aspx"]
[/urlaction][/customaction]
[customaction id="669B5931-0A2C-4446-A73E-0FBEAD549833" title="LA Start Pages" description="Shows the SP Site Start Pages" location="Microsoft.SharePoint.StandardMenu" groupid="SiteActions" sequence="99"]
[urlaction url="~site/Sample/StartPage.aspx"]
[/urlaction][/customaction]
[/elements]
--------
Post Build
cd $(ProjectDir)
Install.bat
--------
Install.Bat
REM – Remember to remove line breaks from first two lines
@SET TEMPLATEDIR="c:\program files\common files\microsoft shared\web server extensions\12\Template"
@SET STSADM="c:\program files\common files\microsoft shared\web server extensions\12\bin\stsadm"
@SET GACUTIL="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\GacUtil.exe"
Echo Copying files
xcopy /e /y TEMPLATE\* %TEMPLATEDIR%
Echo Installing feature
%STSADM% -o InstallFeature -filename Pages\feature.xml -force
Echo Uninstalling the DLL from GAC
%GACUTIL% /u SitePages
Echo Installing the DLL in GAC
Echo %GACUTIL%
%GACUTIL% /i "C:\Partha\Projects\SitePages\bin\Debug\ SitePages.dll"
Echo Restart IIS Worker Process IISRESET
HaPpY CoDinG
Partha (Aurum)