这次我们来实际开发一个webpart的Demo添加到网站的页面上去

打开vs2010,新建project

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

注意在选择部署Debug的位置时要选择一个网站,当然也可以是根站点,这里选择的是Video站点

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

我们将默认的webpart删除,重新添加一个新的命名为WebPartButton

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

打开设计页面,添加一个按钮控件,双击后编写事件

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Write("Hello,WebPart!!");
        }

然后可以启动Debug

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

打开网站进行在线调试,选择编辑网页,以添加webpart

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

添加webpart时,注意断则custom,是你自定义添加的webpart

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

添加完成之后,点击一下看看效果

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

到此时,调试已经可以正常开发了,但是怎么部署呢?

如果你是默认安装的话,本机的Sharepoint根站点有个目录在

C:\inetpub\wwwroot\wss\VirtualDirectories\80

我们先把webpart开发生成的dll文件拷贝到上面这个目录的Bin文件夹内

然后使用Reflector分析一下这个DLL,取得命名空间和DLL的信息

Oracle VM VirtualBox上安装windows server2008R2做SharePointServer2010开发(下)

打开web.config添加节点

<SafeControl Assembly="WebPart1Demo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=a1d39da85a11e887" Namespace="WebPart1Demo.WebPartButton" TypeName="*" Safe="True" />   
</SafeControls>

在编辑网页中,即可上传webpart!

相关文章:

  • 2021-08-20
  • 2021-04-06
  • 2021-06-30
  • 2021-06-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-29
猜你喜欢
  • 2021-05-29
  • 2021-10-19
  • 2021-07-11
  • 2022-12-23
  • 2021-11-28
  • 2021-11-15
相关资源
相似解决方案