BigSeal

程序员之路刚起步

导航

开发我的第一个WebPart

Posted on 2004-09-30 15:49  BigSeal  阅读(355)  评论(0)    收藏  举报

准备开发一个自己的Web Part,收集了不少这方面的东东,但因为是初次接触,适合自己看的内容倒不是很多,有WSS的SDK文档及几篇开发简单Web Part的文章,很感谢提供这些文档的同志们,图文并茂,给开发增添了不少乐趣。虽说是照着这些文档开发,也不是那么一帆风顺的,列出了一些自己觉得有必要注意的地方。
一、前几天把系统和开发环境都配置好了,现在来来尝试着开发自己的第一个WebPart。
Web Part Pages is a special type of Web page that consolidates data such as lists and charts, and Web content such as text and images, into a dynamic information portal built around a common task or special interest. Each Web Part Page contains one or more Web Part zones, which in turn contain one or more Web Parts. Web Parts are the basic building blocks of a Web Part Page.
Web Part is a modular unit of information that has a single purpose and that forms the basic building block of a Web Part Page.
这是Web Part  Page和Web Part的概念。

二、使用VS.Net中的Web Part Library template,这个模板可以从MSDN上下载,下载地址为:
http://www.microsoft.com/downloads/details.aspx?FamilyId=CAC3E0D2-BEC1-494C-A74E-75936B88E3B5&displaylang=en

三、把解决方案文件的输出路径改为虚拟站点的根目录下的bin文件夹

四、实现把Web Part中的文本框的内容作为Title的功能

五、给程序集强命名(不是必须的),但通过强命名可确保用户对WebPart的信任。
 1.通过强命名实用工具(sn.exe) 管理公钥、生成数字签名、验证数字签名
    语法为:
sn.exe -k c:\keypair.snk
 注:应在sdk的安装目录下的命令行执行该命令,默认的路径为:\Program Files\Microsoft Visual  Studio .NET 2003\SDK\v1.1\Bin\

 2.把解决方案中的AssemblyInfo.cs 文件的[assembly: AssemblyKeyFile("")]改为[assembly: AssemblyKeyFile("c:\\keypair.snk")]
 3.用强命名工具生成公钥标记
 语法为:
sn.exe -T c:\inetpub\wwwroot\bin\SimpleWebPart.dll
4.把Web Part的程序集注册为安全控件
 在虚拟站点根目录下的web.config文件的<SafeControls> 块中加入

<SafeControl 
   
Assembly="SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=def148956c61a16b"

   Namespace
="MyWebParts"
   TypeName
="*" 
   Safe
="True"

/>

 六、.创建Web Part定义文件(.DWP)
  文件的格式为:

<?xml version="1.0"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
   
<Assembly>AssemblyName(with no .dll extension), Version=VersionNumber, Culture=Culture, PublicKeyToken=PublicKeyToken</Assembly>
   
<TypeName>WebPartNamespace.WebPartClassName</TypeName>
   
<Title>DefaultWebPartTitle</Title>
   
<Description>WebPartDescription</Description>
</WebPart>

示例文件:

<?xml version="1.0"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2">
   
<Assembly>SimpleWebPart, Version=1.0.0.0, Culture=Neutral, PublicKeyToken=def148956c61a16b</Assembly>
   
<TypeName>MyWebParts.SimpleWebPart</TypeName>
   
<Title>My Simple Web Part</Title>
   
<Description>A sample Web Part</Description>
</WebPart>

七、把Web Part导入到Web Part Page 中