sdtf08 发表于 2019-2-5 08:35:08

用VS2005编写简单WebPart,并加载到Sharepoint2007的站点上去

  文章作者:高维鹏(Brian)文章出处:http://www.cnblogs.com/gaoweipeng
  VS2005,新建项目,在C#里选择Sharepoint模板里的web部件,命名为Brian_HelloWebPart,然后再Brian_HelloWebPart.cs里输入
using System;  
using System.Collections.Generic;
  
using System.Text;
  
using System.Web.UI.WebControls.WebParts;//添加WebParts命名空间
  
namespace Brian_HelloWebPart
  
{

  public>  {
  private string _Text = "Say Hello To Everyone !";
  
  public string Text
  {
  get { return _Text; }
  set { _Text = value; }
  }
  protected override void Render(System.Web.UI.HtmlTextWriter writer)
  {
  writer.Write(_Text);
  }
  }
  
}
  然后在AssemblyInfo.cs文件里,开头加入
using System.Security;  最下面添加这句,主要目的是放在bin是部分信任的程序,便于全信任。
  然后,点击项目生成,从项目C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Brian_HelloWebPart\Brian_HelloWebPart\bin\Debug里找到刚生成的Brian_HelloWebPart.dll,拷贝到你的站点位置http://10.2.22.112:81/default.aspx,即C:\Inetpub\wwwroot\wss\VirtualDirectories\81\bin里。
  然后用Visual Studio 2005 命令提示,按照如下方式操作,获取PublicKeyToken。http://images.cnblogs.com/cnblogs_com/gaoweipeng/webpart5.jpg
  然后编辑同目录下的Web.config中添加如下代码:
  到此,我们的WebPart就部署完毕了!
  -----------------------------------------------------------------------------------------------------------------------------------------------
  
  在SharePoint站点中添加WebPart
http://images.cnblogs.com/cnblogs_com/gaoweipeng/webpart6.jpg
  第二步
http://images.cnblogs.com/cnblogs_com/gaoweipeng/webpart7.jpg
  第三步,进入Web部件库中我们就可以看到要添加的HelloWebPart,选中后点击“导入库”:
http://images.cnblogs.com/cnblogs_com/gaoweipeng/webpart8.jpg
  第四步
http://images.cnblogs.com/cnblogs_com/gaoweipeng/webpart9.jpg


页: [1]
查看完整版本: 用VS2005编写简单WebPart,并加载到Sharepoint2007的站点上去