使用类库方式做简单的webpart

it2022-05-07  41

使用类库方式做简单的webpart

一.创建类库

1.在VS2005中新建项目,选择类库模板

名称为webpart.hello,建好工程后将类名改为hello

添加引用System.Web

hello.cs的代码如下

using  System; using  System.Text; using  System.Collections.Generic; using  System.Web.UI; using  System.Web.UI.WebControls.WebParts; namespace  webpart.hello{     public   class  hello:WebPart    {          private   string  _Text  =   " Hello World! " ;        [WebBrowsable( true ), Personalizable( true )]         public   string  Text        {             get  {  return  _Text; }             set  { _Text  =  value; }        }         protected   override   void  Render(HtmlTextWriter writer)        {            writer.Write(_Text);        }    }}

在AssemblyInfo.cs中添加如下代码

using System.Security;

[assembly: AllowPartiallyTrustedCallers()]

 

2.生成一个强名文件

a在解決方案中右键单击工程名,在弹出的菜单中选择属性,则可以打开工程的属性框,在属性框中选择签名页。

 

b为程序集签名 新建密钥文件 输入密钥文件名称,如Key.snk

 

c去掉使用密码保护密钥文件的勾

 

 

3.编译工程, 生成dll程序集

二.Webpart的配置

1打开sharepoint站点根目录,如D:\Inetpub\wwwroot\wss\VirtualDirectories\81

将编译好的webpart.hello.dll 复制到_app_bin文件夹中

2打开web.config文件,在其中<SafeControl>……</SafeControl>节下添加一行配置信息,注册为安全控件

< SafeControl  Assembly ="webpart.hello, Version=1.0.0.0, Culture=neutral, PublicKeyToken=097a8a537807300c"  Namespace ="webpart.hello"  TypeName ="hello"  Safe ="True"   /> TypeName 为类名

 

 

 

 

posted on 2007-01-08 13:07 天堂草 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/kame/archive/2007/01/08/614777.html


最新回复(0)