views:

32

answers:

1

I am attempting to for the first time create a custom asp.net website on a sharepoint web server, i have created the following Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" MasterPageFile="~/_layouts/application.master" %>
<%@ Assembly Name="Microsoft.SharePoint.ApplicationPages,Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>


<asp:Content ID="Content1" ContentPlaceHolderId="PlaceHolderMain" runat="server">
    <div>
    Title of this site: <asp:Label ID="LabelTitle" runat="server" Text="Label">
    </asp:Label>
    </div>
</asp:Content>

<asp:Content ID="Content2" 
ContentPlaceHolderId="PlaceHolderPageTitleInTitleArea" runat="server">
Test ASP.NET 2.0 Application
</asp:Content>

with the following Default.aspx.cs

using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using Microsoft.SharePoint;


public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SPWeb web = SPcontext.Current.Web;
        LabelTitle.Text = web.Title;
    }

    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);

        SPWeb web = SPContext.Current.Web;

        String strUrl = web.ServerRelativeUrl + "/_catalogs/masterpage/default.aster";

        this.MasterPageFile = strUrl;
    }
}

I also commented out in the web.config, and I included the Microsoft.Sharepoint.dll as a reference in the project. I then dropped the entire folder under _layouts\TestWebsite\

However, when going to http://server/_layouts/TestWebSite/ I get a 'File not Found' error. Is there something I am missing or a setting that I should have skipped over?

Thanks.

A: 

You need to set up your Page directive differently and you can't use the normal way of adding an ASP.net page to a project.

Add your assembly

<%@ Assembly Name="Your.Four.Part.AssemblyName" %>

Next remove the CodeFile attribute and replace default.aspx.cs in the Inherits attribute with the name of the page class in your assembly.

Your page directive should look something like this:

<%@ Page Language="C#" Inherits="NameSpace.ClassNameInCodeBehind" MasterPageFile="~/_layouts/application.master" %>

If you do a search for "code behind in SharePoint" you will find lots of articles like this one: http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

It also helps to get WSPBuilder or STSDev for projects like this. STSDev even has an Application Page with Navigation project template that will get you going quickly.

Junx