· Create a web application using Visual Studio (2005 or better).
· In the build options change the Output path to the web front end of the SharePoint server. I.e. \\server\C$\Inetpub\wwwroot\wss\VirtualDirectories\80\bin. This has to be done for each sharepoint site that you want to run the code.
· Go ahead and make your page the way you want.
· Build the page.
· Add a reference to Microsoft.SharePoint.dll. If you are developing on a machine that does not SharePoint you can copy the file into the bin directory of your project (you can temporarily remove it when you build the project to avoid the transfer).
· In the code behind page put the following two lines
o using Microsoft.SharePoint;
o using Microsoft.SharePoint.WebControls;
In your partial class add this code.
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);
SPWeb spWeb = SPControl.GetContextSite(Context).OpenWeb();
string strURL = spWeb.ServerRelativeUrl + "/_catalogs/masterpage/default.master"; //this can be changed to the master page you desire.
this.MasterPageFile = strURL;
}
· Build the project
· Go to the SharePoint server and navigate to the hive i.e. C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS
· Create a directory to place your code (i.e. mycode)
· Copy in your aspx and aspx.cs files into your newly created directory.
You will need to edit the aspx file. Basically start with this
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testmaster.aspx.cs" Inherits="testmaster" %>
<asp:Content contentplaceholderid="PlaceHolderMain" runat="server">
//Insert your code here
<asp:Label ID="Label1" runat="server" Width="168px"></asp:Label>
</asp:Content>
· Copy everything from the original aspx page that exists between the form tags and put it between the asp:content tags.
· You will now have code that can be run from _layouts/mycode (or whatever you named it)