在sharepoint _layouts文件夹中创建自定义webapp

时间:2010-07-20 22:23:54

标签: c# asp.net sharepoint

我试图第一次在sharepoint网络服务器上创建一个自定义的asp.net网站,我创建了以下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>

使用以下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;
    }
}

我还在web.config中注释掉了,并且我在项目中包含了Microsoft.Sharepoint.dll作为参考。然后我将整个文件夹放在_layouts \ TestWebsite \

然而,当转到http://server/_layouts/TestWebSite/时,我收到了“找不到文件”错误。是否有我遗漏的东西或我应该跳过的设置?

感谢。

1 个答案:

答案 0 :(得分:0)

您需要以不同方式设置Page指令,并且不能使用将ASP.net页面添加到项目的常规方法。

添加你的程序集

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

接下来删除CodeFile属性,并将Inherits属性中的default.aspx.cs替换为程序集中页面类的名称。

您的页面指令应如下所示:

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

如果您搜索“SharePoint背后的代码”,您会发现很多类似这样的文章:http://www.andrewconnell.com/blog/articles/UsingCodeBehindFilesInSharePointSites.aspx

对于像这样的项目,它也有助于获得WSPBuilder或STSDev。 STSDev甚至还有一个带有导航项目模板的应用程序页面,可以帮助您快速上手。