一步一步SharePoint 2007之二十三:编写一个最简单的WebPart(1)——创建工程
考虑到编写一个最简单的WebPart的文章共有20多幅截图,截图总大小近2M,为了尽量减少打开网页的时间,本篇文章将被分割成几个小的部分。因此而给大家带来的阅读不便,就请海涵了:)本篇文章将创建一个WebPart工程。
为了方便您的学习,您可以下载本篇文章所创建的工程。单击此处下载。
下面将记录每一步的操作过程。
1、首先Visual Studio 2005,在菜单中依次选择File,New,Project。
http://blog.运维网.com/attachment/200805/200805261211790575875.jpg
2、单击Project后,即弹出New Project对话框。这里我们选择创建一个C#语言的Class Library工程,工程名称为Eallies.WebParts.Hello。
http://blog.运维网.com/attachment/200805/200805261211790590687.jpg
3、新建工程完毕后,将默认的Class1改名为Instance,则整个工程就是这样的:
http://blog.运维网.com/attachment/200805/200805261211790603156.jpg
4、在右边的Solution Explorer中,右键单击References,在弹出的菜单中选择Add Reference,则弹出Add Reference对话框。这里我们选择Component Name为System.Web。
http://blog.运维网.com/attachment/200805/200805261211790619796.jpg
5、添加完Reference后,我们打开Instance.cs,将其代码更改为:
http://blog.运维网.com/attachment/200805/200805261211790633046.jpg
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 AssemblyTitle("Hello")]
10 AssemblyDescription("")]
11 AssemblyConfiguration("")]
12 AssemblyCompany("Eallies Corporation")]
13 AssemblyProduct("Hello")]
14 AssemblyCopyright("Copyright ? Eallies Corporation 2006")]
15 AssemblyTrademark("")]
16 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 ComVisible(false)]
22
23 // The following GUID is for the ID of the typelib if this project is exposed to COM
24 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 AssemblyVersion("1.0.0.0")]
36 AssemblyFileVersion("1.0.0.0")]
37
38 AllowPartiallyTrustedCallers()]
这里,我们实际上只是引用了System.Security,然后加上了这一行代码。
http://blog.运维网.com/attachment/200805/200805261211790648500.jpg
至此,WebPart工程即创建完毕。
下一篇文章我将记录如何编写一个最简单的WebPart的第二部分。欢迎大家继续关注:)多谢!
附件:http://down.运维网.com/data/2349991
页:
[1]