一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程
| 摘要 |
| 在前面的文章中,我們講解了很多基礎(chǔ)的內(nèi)容,主要包括安裝配置、Form認證等。可能這些對很多朋友來說,是太容易了。那么,從下一篇文章開始,就讓我們進入SharePoint的高級課題之旅吧。 本篇文章將介紹如何編寫一個最簡單的WebPart。 跟所有的編程技術(shù)一樣,都是從編寫第一個Hello World程序開始的。筆者自嘆也是一個俗人,所以當然也不能免俗,我們就也從編寫一個Hello World的WebPart開始吧! |
| 正文 |
| 考慮到編寫一個最簡單的WebPart的文章共有20多幅截圖,截圖總大小近2M,為了盡量減少打開網(wǎng)頁的時間,本篇文章將被分割成幾個小的部分。因此而給大家?guī)淼拈喿x不便,就請海涵了:) 本篇文章將創(chuàng)建一個WebPart工程。 為了方便您的學習,您可以下載本篇文章所創(chuàng)建的工程。單擊此處下載。 下面將記錄每一步的操作過程。 1、首先Visual Studio 2005,在菜單中依次選擇File,New,Project。 2、單擊Project后,即彈出New Project對話框。這里我們選擇創(chuàng)建一個C#語言的Class Library工程,工程名稱為Eallies.WebParts.Hello。 3、新建工程完畢后,將默認的Class1改名為Instance,則整個工程就是這樣的: 4、在右邊的Solution Explorer中,右鍵單擊References,在彈出的菜單中選擇Add Reference,則彈出Add Reference對話框。這里我們選擇Component Name為System.Web。 5、添加完Reference后,我們打開Instance.cs,將其代碼更改為: ????1?using System; ????2?using System.Collections.Generic; ????3?using System.Text; ????4?using System.Web.UI.WebControls.WebParts; ????5? ????6?namespace Hello ????7?{ ????8???? public class Hello : WebPart ????9???? { ???10???? ??? private string _Text = "Hello World!"; ???11? ???12???? ??? [WebBrowsable(true), Personalizable(true)] ???13???? ??? public string Text ???14???? ??? { ???15???? ??? ??? get { return _Text; } ???16???? ??? ??? set { _Text = value; } ???17???? ??? } ???18???? ??? protected override void Render(System.Web.UI.HtmlTextWriter writer) ???19???? ??? { ???20???? ??? ??? writer.Write(_Text); ???21???? ??? } ???22???? } ???23?} 6、然后再打開Properties\AssemblyInfo.cs,將其代碼更改為: ????1?using System.Reflection; ????2?using System.Runtime.CompilerServices; ????3?using System.Runtime.InteropServices; ????4?using System.Security; ????5? ????6?// General Information about an assembly is controlled through the following ????7?// set of attributes. Change these attribute values to modify the information ????8?// associated with an assembly. ????9?[assembly: AssemblyTitle("Hello")] ???10?[assembly: AssemblyDescription("")] ???11?[assembly: AssemblyConfiguration("")] ???12?[assembly: AssemblyCompany("Eallies Corporation")] ???13?[assembly: AssemblyProduct("Hello")] ???14?[assembly: AssemblyCopyright("Copyright ? Eallies Corporation 2006")] ???15?[assembly: AssemblyTrademark("")] ???16?[assembly: AssemblyCulture("")] ???17? ???18?// Setting ComVisible to false makes the types in this assembly not visible ???19?// to COM components.? If you need to access a type in this assembly from ???20?// COM, set the ComVisible attribute to true on that type. ???21?[assembly: ComVisible(false)] ???22? ???23?// The following GUID is for the ID of the typelib if this project is exposed to COM ???24?[assembly: Guid("8318200d-9059-4b4e-81db-c146659bd89d")] ???25? ???26?// Version information for an assembly consists of the following four values: ???27?// ???28?//??? ? Major Version ???29?//??? ? Minor Version ???30?//??? ? Build Number ???31?//??? ? Revision ???32?// ???33?// You can specify all the values or you can default the Revision and Build Numbers ???34?// by using the '*' as shown below: ???35?[assembly: AssemblyVersion("1.0.0.0")] ???36?[assembly: AssemblyFileVersion("1.0.0.0")] ???37? ???38?[assembly: AllowPartiallyTrustedCallers()] 這里,我們實際上只是引用了System.Security,然后加上了[assembly: AllowPartiallyTrustedCallers()]這一行代碼。至此,WebPart工程即創(chuàng)建完畢。 下一篇文章我將記錄如何編寫一個最簡單的WebPart的第二部分。歡迎大家繼續(xù)關(guān)注:)多謝! |
轉(zhuǎn)載于:https://www.cnblogs.com/wayne-ivan/archive/2007/09/15/894148.html
總結(jié)
以上是生活随笔為你收集整理的一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C#中out 及 ref 区别
- 下一篇: 《播客》项目总结——web标准页面设计方