创建Sharepoint空项目:
创建了一个空的项目文件:
添加引用:
选择要引用的DLL:
添加引用的DLL:
继续添加Sharepoint.dll的引用:
下载Microsoft的Enterprise Library 4.1版本的Hands On Labs的安装文件,因为 Hands On Labs的DLL文件是强签名的,
而Enterprise Library 4.1的源码编译出来的DLL不是强签名的。要想在Sharepoint里面使用Enterprise Library的DLL,这些DLL必须是强签名的才行;
用默认的选项安装了Enterprise Library for .NET Framework 3.5(v4.1) Hands On Labs后,安装包会把相关的DLL拷贝到以下目录:
C:/Enterprise Library 4.1 HOL/Lib
继续给工程文件添加Enterprise Library 4.1的这两个DLL:
添加了Enterprise Library的DLL后的工程文件:
用右键查看Microsoft.Practices.EnterpriseLibray.Data这个DLL的属性,可以看到这个DLL是强签名的:
接着在工程里面按照以下目录创建存放我们要创建的*.aspx文件的文件夹:
选择新建文件菜单:
选择以下文件类型:
创建后的aspx文件:
按VS2008工具栏上面的保存按钮,以Orders.aspx命名保存这个文件到工程里面的EnLibWss目录:
然后把Orders.aspx文件添加到工程里面来:
在VS2008里面打开这个Orders.aspx文件:
把默认的内容换成以下代码,主要是要使Orders.aspx这个页面要使用到application.master这个母版页:
Enterprise Library 4.1 & Sharepoint
Enterprise Library 4.1 & Sharepoint
给Orders.aspx创建CodeBehind类:
把Orders.cs文件的内容改为如下,使Orders类继承:LayoutsPageBase 类;
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
namespace EnLibWss
{
public class Orders : LayoutsPageBase
{
protected GridView gvOrders;
protected TextBox tbMsg;
protected override void OnLoad(EventArgs e)
{
try
{
Database db = DatabaseFactory.CreateDatabase("MyConnectionString");
DataSet dsCustomer = db.ExecuteDataSet(CommandType.Text, " SELECT TOP 10 * FROM Sales.SalesOrderHeader ");
gvOrders.DataSource = dsCustomer.Tables[0].DefaultView;
gvOrders.DataBind();
}
catch (Exception ex)
{
tbMsg.Text = ex.Message;
}
}
}
}
分别把引用里面的Microsoft.Practices.EnterpriseLibrary.Common.dll和Microsoft.Practices.EnterpriseLibrary.Data.dll这两个DLL的“复制本地”属性改为:True
在工程里面创建一个名为intall.bat的批处理文件,并添加以下内容到install.bat文件里面,保存:
@SET TEMPLATEDIR="c:/program files/common files/microsoft shared/web server extensions/12/Template"
@SET STSADM="c:/program files/common files/microsoft shared/web server extensions/12/bin/stsadm"
@SET GACUTIL="C:/Program Files/Microsoft SDKs/Windows/v6.0A/Bin/gacutil.exe"
IISRESET
REM cscript c:/windows/system32/iisapp.vbs /a "SharePointDefaultAppPool" /r
Echo Installing EnLibWss.dll in GAC
%GACUTIL% -if bin/debug/EnLibWss.dll
Echo Installing Microsoft.Practices.EnterpriseLibrary.Common.dll in GAC
%GACUTIL% -if bin/debug/Microsoft.Practices.EnterpriseLibrary.Common.dll
Echo Installing Microsoft.Practices.EnterpriseLibrary.Data.dll in GAC
%GACUTIL% -if bin/debug/Microsoft.Practices.EnterpriseLibrary.Data.dll
Echo Copying files
xcopy /e /y TEMPLATE/* %TEMPLATEDIR%
然后在工程文件的属性页里面的“生成事件”里面增加这两行命令:
cd $(ProjectDir)
install.bat
这样就可以在每次编译后,VS2008把相关文件拷贝到Sharepoint的目录里面;
现在编译工程文件,Install.bat文件自动把相关的文件拷贝的Sharepoint的网站目录下面:
打开WSS的网站的虚拟目录里面的Web.config文件:
增加数据库链接字符串的配置内容:(我这里用到SQL Server 2005的示例数据库AdventureWorks)
providerName="System.Data.SqlClient" />
然后增加Enterprise Library DLL的引用内容:
保存Web.config文件后在IE浏览器里面打开我们创建的那个Order.aspx页面,可以看到,Enterprise Library能够运行该SQL,并返回相应的数据显示在GridView控件里面:
当然,以上只是把Enterprise Library 4.1引入WSS环境的一个简单的方法,真正的业务系统,应该将工程分为业务层、表现层、数据存储层等多层的架构,然后再将系统用以上方法部署到WSS环境中去;
本文介绍如何在SharePoint环境中集成Microsoft Enterprise Library 4.1,包括创建项目、添加必需的DLL引用、部署步骤及配置Web.config文件等内容。
![clip_image002[7] clip_image002[7]](http://hi.youkuaiyun.com/attachment/201010/9/0_128659366574F8.gif)
![clip_image002[9] clip_image002[9]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593670I0jI.gif)

![clip_image002[16] clip_image002[16]](http://hi.youkuaiyun.com/attachment/201010/9/0_12865936721y2K.gif)
![clip_image002[18] clip_image002[18]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593674NfZw.gif)
![clip_image002[20] clip_image002[20]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593675NYjl.gif)
![clip_image002[22] clip_image002[22]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593677XU2R.gif)
![clip_image002[24] clip_image002[24]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593679v11s.gif)
![clip_image002[26] clip_image002[26]](http://hi.youkuaiyun.com/attachment/201010/9/0_128659368165pf.gif)
![clip_image002[28] clip_image002[28]](http://hi.youkuaiyun.com/attachment/201010/9/0_12865936821F00.gif)
![clip_image002[30] clip_image002[30]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593683EKZ3.gif)
![clip_image002[32] clip_image002[32]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593684y1Fv.gif)
![clip_image002[34] clip_image002[34]](http://hi.youkuaiyun.com/attachment/201010/9/0_12865936865r55.gif)
![clip_image002[36] clip_image002[36]](http://hi.youkuaiyun.com/attachment/201010/9/0_12865936872da7.gif)
![clip_image002[38] clip_image002[38]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593689j0JJ.gif)
![clip_image002[40] clip_image002[40]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593690bcKx.gif)
![clip_image002[42] clip_image002[42]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593692osEo.gif)
![clip_image002[44] clip_image002[44]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593693Drdb.gif)
![clip_image002[46] clip_image002[46]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593694L4Y1.gif)
![clip_image002[48] clip_image002[48]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593696O3nI.gif)
![clip_image002[52] clip_image002[52]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593700za6J.gif)
![clip_image002[54] clip_image002[54]](http://hi.youkuaiyun.com/attachment/201010/9/0_1286593701iQZk.gif)
![clip_image002[64] clip_image002[64]](http://hi.youkuaiyun.com/attachment/201010/9/0_12865937091xCq.gif)



19

被折叠的 条评论
为什么被折叠?



