如何在WSS中使用Microsoft Enterprise Library

创建Sharepoint空项目:

clip_image002[7]

创建了一个空的项目文件:

clip_image002[9]

添加引用:

clip_image002

选择要引用的DLL:

clip_image002[16]

添加引用的DLL:

clip_image002[18]

继续添加Sharepoint.dll的引用:

clip_image002[20]

下载Microsoft的Enterprise Library 4.1版本的Hands On Labs的安装文件,因为 Hands On Labs的DLL文件是强签名的,

下载地址是:http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ab3f2168-fea1-4fc2-b40c-7867d99d4b6a

而Enterprise Library 4.1的源码编译出来的DLL不是强签名的。要想在Sharepoint里面使用Enterprise Library的DLL,这些DLL必须是强签名的才行;

clip_image002[22]

用默认的选项安装了Enterprise Library for .NET Framework 3.5(v4.1) Hands On Labs后,安装包会把相关的DLL拷贝到以下目录:

C:/Enterprise Library 4.1 HOL/Lib

clip_image002[24]

继续给工程文件添加Enterprise Library 4.1的这两个DLL:

clip_image002[26]

添加了Enterprise Library的DLL后的工程文件:

clip_image002[28]

用右键查看Microsoft.Practices.EnterpriseLibray.Data这个DLL的属性,可以看到这个DLL是强签名的:

clip_image002[30]

接着在工程里面按照以下目录创建存放我们要创建的*.aspx文件的文件夹:

clip_image002[32]

选择新建文件菜单:

clip_image002[34]

选择以下文件类型:

clip_image002[36]

创建后的aspx文件:

clip_image002[38]

按VS2008工具栏上面的保存按钮,以Orders.aspx命名保存这个文件到工程里面的EnLibWss目录:

clip_image002[40]

然后把Orders.aspx文件添加到工程里面来:

clip_image002[42]

clip_image002[44]

在VS2008里面打开这个Orders.aspx文件:

clip_image002[46]

 

把默认的内容换成以下代码,主要是要使Orders.aspx这个页面要使用到application.master这个母版页:





   
   
   


    Enterprise Library 4.1 & Sharepoint       


    Enterprise Library 4.1 & Sharepoint

clip_image002[48]

给Orders.aspx创建CodeBehind类:

clip_image002[50]

clip_image002[52]

把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;

 

            }

 

        } 

 

    }

 

}

clip_image002[54]

 

分别把引用里面的Microsoft.Practices.EnterpriseLibrary.Common.dll和Microsoft.Practices.EnterpriseLibrary.Data.dll这两个DLL的“复制本地”属性改为:True

clip_image002[56]

在工程里面创建一个名为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%

clip_image002[58]

然后在工程文件的属性页里面的“生成事件”里面增加这两行命令:

cd $(ProjectDir)

install.bat

这样就可以在每次编译后,VS2008把相关文件拷贝到Sharepoint的目录里面;

clip_image002[60]

现在编译工程文件,Install.bat文件自动把相关的文件拷贝的Sharepoint的网站目录下面:

clip_image002[62]

clip_image002[64]

打开WSS的网站的虚拟目录里面的Web.config文件:

image

增加数据库链接字符串的配置内容:(我这里用到SQL Server 2005的示例数据库AdventureWorks)


          providerName="System.Data.SqlClient" />

image

然后增加Enterprise Library DLL的引用内容:

 

image

保存Web.config文件后在IE浏览器里面打开我们创建的那个Order.aspx页面,可以看到,Enterprise Library能够运行该SQL,并返回相应的数据显示在GridView控件里面:

clip_image002[66]

当然,以上只是把Enterprise Library 4.1引入WSS环境的一个简单的方法,真正的业务系统,应该将工程分为业务层、表现层、数据存储层等多层的架构,然后再将系统用以上方法部署到WSS环境中去;

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值