SharePoint 2007 WebPart Sample[範本]
[ Base On Visual Studio 2005, C#.Net ]
.首先透過 Visual Studio 建立一個專案,類型為類別庫
First,use visual studio bulid class of protect.
.加入SharePoin t的參考,using Microsoft.SharePoint;
Add Microsoft.SharePoint.dll;
.撰寫程式,這裡我就不多說了,自己複製程式吧
copy code
using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI; namespace SampleWebPart { public class SampleWebPart:System.Web.UI.WebControls.WebParts.WebPart { private string _Message = System.DateTime.Now.Date.ToString(); [WebBrowsable(true), Personalizable(true)] [WebDisplayName("您要顯示的時間"), WebDescription("您要顯示的時間")] public string Message { get { return _Message; } set { _Message = value; } } public SampleWebPart() { this.ExportMode = WebPartExportMode.All; } protected override void Render(HtmlTextWriter writer) { DateTime time = new DateTime(); //Show writer.Write(Message); base.Render(writer); } } }
.完成之後編輯,會產DLL檔案,將此DLL加到assembly(C:\WINDOWS\assembly)
with dll add to assembly
.到C:\Inetpub\wwwroot\wss\VirtualDirectories\[port]\內的webconfig檔修改參數,請依照你的key輸入正確的值
Fallow path "C:\Inetpub\wwwroot\wss\VirtualDirectories\[port]\",edit webconfig to add your safeControl
<SafeControl Assembly="SampleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=e4af32310553f9c4" Namespace="SampleWebPart" TypeName="*" Safe="True" />
.先iisreset在至Moss網站中->網站動作->網站設定->網頁組件->新增
do iisreset then in SharePoint Web -> site action -> site setting -> web part –> add
.回到編輯頁面加入新的網頁組件就會看到我們所建立的webpart
add new webpart ,you can see our craete webpart.
完成
End.