天天看點

定制Sharepoint 2010表單頁面(DispForm.aspx)

在《WSS3.0開發--頁面定制(1)--修改清單的表單頁面》和《WSS頁面定制系列(2)---定制單個清單的表單頁面》已經很詳細了介紹了在WSS3.0中的定制的方法。方法1,使用Sharepoint Designer寫RenderingTemplate;方法2,直接修改DispForm.aspx頁面,隐藏原有的表單内容,重寫頁面。第一個方法明顯具有優勢,可複用性高。

按照那篇文章說的一步一步做。

首先,在 C:\Program Files\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\CONTROLTEMPLATES目錄中有一個DefaultTemplates.ascx檔案,這個檔案就是很多模闆控件。找到

<SharePoint:RenderingTemplate ID="ListForm" runat="server">

…………

</SharePoint:RenderingTemplate>

這個控件。

然後,把這部分複制,在CONTROLTEMPLATES檔案夾下建立一個CustomListForm.ascx檔案(這個檔案名無所謂),把剛才複制的内容粘貼到這個檔案中。然後再把DefaultTemplates.ascx頭部的代碼複制添加到CustomListForm.ascx的頭部,代碼如下:

<%@ Control Language="C#"   AutoEventWireup="false" %>

<%@Assembly Name="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>

<%@Register TagPrefix="ApplicationPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.ApplicationPages.WebControls"%>

<%@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>

<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="_controltemplates/ToolBar.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="_controltemplates/ToolBarButton.ascx" %>

接着,加上3條橫線,按照參考文章進行的。

…………

<SPAN id='part1'>

<hr/>

<hr/>

<hr/>

<SharePoint:InformationBar runat="server"/>

…………

把DispForm.aspx中<TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">ListForm</TemplateName>改成TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">CustomListForm</TemplateName>,這個是清單模闆名稱,不是檔案的名稱。

再重新開機IIS,重新整理看效果。

定制Sharepoint 2010表單頁面(DispForm.aspx)

咦!沒效果!在Sharepoint2010中不能這麼定制?

找原因開始!在網上搜了一下也沒找到什麼,可能用2010的還不是特别多吧。

打開事件檢視器,在應用程式日志中發現了這麼一個錯誤:

加載控件模闆檔案 /_controltemplates/CustomListForm.ascx 失敗: 檔案“/_controltemplates/_controltemplates/ToolBar.ascx”不存在。

怎麼會是檔案“/_controltemplates/_controltemplates/ToolBar.ascx”不存在,路徑不對,删除一個檔案夾路徑

頭部代碼的最後兩行就改成了

<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="ToolBar.ascx" %>

<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="ToolBarButton.ascx" %>

儲存,重新開機IIS,重新整理看效果。

定制Sharepoint 2010表單頁面(DispForm.aspx)

三條橫線出現了,這樣就可以開始個性化定制頁面了。

轉載于:https://www.cnblogs.com/zhujian/archive/2011/03/05/1971460.html

c#