2010-07-20 83 views
0

我試圖首次創建SharePoint Web服務器上的自定義asp.net網站,我已經創建了下面的Default.aspx在SharePoint _layouts文件夾中創建自定義Web應用

<%@ 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> 

與下面的默認.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/時,出現'文件未找到'錯誤。有什麼我失蹤或我應該跳過的設置?

謝謝。

回答

0

您需要以不同的方式設置您的Page指令,並且不能使用將ASP.net頁面添加到項目的常規方式。

添加您的裝配

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

然後拆掉的CodeFile屬性,並與在彙編頁面類的名稱的繼承屬性替換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甚至有一個帶導航的應用程序頁面項目模板,可以幫助您快速完成任務。

相關問題