您的位置:首页 > 其它

sharepoint 2007webpart开发笔记(20080506)。

2008-05-06 01:37 393 查看
搞了N天的webpart,快死了,才发现网上的很多文章好像都有误区,按网上的文章都没有做成,现在总算措到点门道,将测试的N个DEMO都部署成功了。高兴高兴。

我还是个门外汉。记录下来供以后忘记的时间参考用用。

一、sharepoint 2007webpartCOPY部署的办法:
将生成的DLL文件COPY到BIN目录下(注意是BIN,不是APP_BIN目录)。
然后在web.config文件中添加对控件的安全信任的代码:
如:
<SafeControl Assembly="TestWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="TestWebParts" TypeName="*" Safe="True" />

然后点击moss的管理中心的“网站设置/web部件”。将打开一个页面,显示了一些web部件。
选择“新建web部件”,在打开的页面中的最后,就会出现新添加的web部件:TestWebParts.SimpleWebPart。
选择该部件,然后点击“导入库”按钮。这样,新添加的web部件就出现在了“Web部件库”的页面上。
就可以使用该部件了。

在moss配置完毕后生成的主页上使用该部件。
导入库后,虽然可以在部件库中看到该部件,但在配置生成的主页中,修改页面并添加部件时,并没有找到该部件。iisreset后也没有,为什么呢?
但在管理中心的页面编辑中可以找到该部件。但生成的主页中的“网站设置”中并没有找到可以部署webpart的东东(这可能就是所说的想在那个网站上用这个webpart,就部署在那个网站上吧。时间太紧,今天就不去研究这个了。)。

二、开发部署过程中发现的几个要点:
1、copy部署是将DLL文件放在Bin目录下,而不是_app_bin目录下。
2、Copy部署并不需要重新启动IIS。
3、在“导入库”的列表中,显示的是部件的Namespace.classname,如:
TestWebPartsZdr_NameSpace.TestWebPartsZdr_Class
4、web.config中的代码如下:
<SafeControl Assembly="TestWebPartsZdr_DllName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="TestWebPartsZdr_NameSpace" TypeName="*" Safe="True" />
该webpart的CS代码如下:

using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.WebControls;

namespace TestWebPartsZdr_NameSpace
{
public class TestWebPartsZdr_Class : WebPart
{
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write("钟德荣的Hello World!");
//base.RenderContents(writer);
}

}
}

assemblyinfo.cs的源代码如下:

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;

// 有关程序集的常规信息通过下列属性集
// 控制。更改这些属性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("SimpleWebPart")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("番茄花园")]
[assembly: AssemblyProduct("SimpleWebPart")]
[assembly: AssemblyCopyright("版权所有 (C) 番茄花园 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 属性设置为 true。
[assembly: ComVisible(false)]

// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("04958120-c15f-47bc-9d24-e7adbb618684")]

// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 内部版本号
// 修订号
//
// 可以指定所有这些值,也可以使用“修订号”和“内部版本号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

5、copy部署时,还需要进行“新建/导入库”操作。
6、开发的webPart类必须从webPart类继承。
7、并不需要在Assemblyinfo文件中增加这行代码:[assembly:AllowPartiallyTrustedCallers()]
关于这个可能是生成强签名才用的吧(待研究)。

8、在上面成功的webpart中,我也没有添加Microsoft.SharePoint.dll的文件引用。

也没有添加using System.Security;这行代码(assemblyinfo.cs文件也没有添加)

部署并引用后的效果如下:



部署后的网站的webconfig注册安全性的脚本如下:

<WebPartControls DatasheetControlGuid="65BCBEE4-7728-41a0-97BE-14E1CAE36AAE" />
<SafeControls>
<SafeControl Assembly="TestWebPartsZdr_DllName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="TestWebPartsZdr_NameSpace" TypeName="*" Safe="True" />
<SafeControl Assembly="TestWebPartsZdr, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="TestWebPartsZdr" TypeName="*" Safe="True" />
<SafeControl Assembly="TestWebParts, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" Namespace="TestWebParts" TypeName="*" Safe="True" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: