考慮到編寫一個最簡單的WebPart的文章共有20多幅截圖,截圖總大小近2M,為了盡量減少打開網頁的時間,本篇文章将被分割成幾個小的部分。是以而給大家帶來的閱讀不便,就請海涵了:)
本篇文章将建立一個WebPart工程。
下面将記錄每一步的操作過程。
1、首先Visual Studio 2005,在菜單中依次選擇File,New,Project。
2、單擊Project後,即彈出New Project對話框。這裡我們選擇建立一個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,将其代碼更改為:
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工程即建立完畢。
本文轉自 Eallies 51CTO部落格,原文連結:http://blog.51cto.com/eallies/78827,如需轉載請自行聯系原作者