Click here to Skip to main content
Click here to Skip to main content

Using Microsoft Enterprise Library Application Block in SharePoint

, 21 Nov 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
This article will tell how to use Microsoft Enterprise Library Application blocks in a Sharepoint site

Introduction

Everyone who uses Sharepoint sites, will be using database access for displaying data in your Sharepoint sites. The accessing of Database is made easier by the Microsoft Enterprise Library Application blocks. But unfortunately the Application Block DLLs cannot be directly used in our sharepoint sites. The MSEL DLLs may work fine in an ordinary ASP.NET web application scenario but when one wants to make this ASP.NET application into a Sharepoint application, we need to do some tweaks and this article is written for that purpose.

Background

The MSEL Application Block DLLs are not strong named when it comes with the package. This is for various reasons. But when we wnat to use it in our Sharepoint site, then it has to be Strong named. Also the DLLs that have to be used in the Sharepoint site must be compiled with Partially trusted so that any page in your application can use this in your Sharepoint site.

Application Versions

Microsoft Enterprise Library Application Block (MSEL): January 2006 with Patch 2554

SharePoint: SharePoint Server 2007

Visual Studio: Visual Studio 2005

Download References

MSEL January 2006 Download link: http://www.microsoft.com/downloads/details.aspx?FamilyID=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en

Patch 2554 for MSEL download link: http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=1339

Prerequisite

MSEL must be Installed and the Application blocks compiled (This is a step during installation of MSEL).

Steps

The first step is to compile and create signed Enterprise Library DLLs. For that we need to do the following

  1. Compiling the Enterprise Library Application blocks
  2. Extract the Patch 2554 for MSEL Application Block.
  3. Copy the Src and UnitTests folders, which are included in the patch archive file, over the existing Src and UnitTests file installed with Enterprise Library. (By default, the Enterprise Library is located at C:\Program Files\Microsoft Enterprise Library January 2006). Applying the patch will overwrite a number of existing source files with new versions that are supplied with the patch.
  4. Open the EnterpriseLibrary solution (EnterpriseLibrary.sln – By default, located at C:\Program Files\Microsoft Enterprise Library January 2006).

The solution will contain project code for all the application blocks as shown below

Screenshot - MSEL-Code.jpg

5. Here, you will have to do the following for the Application block DLLs that you will be using in your project.

6. First, you have to strong name the DLL.

Steps for Strong Naming a DLL

a. Create a strong name key by using the sn –k sample.snk command

b. Right Click on the Class library project that you want to strong name and click Properties

c. Go to the Signing tab

d. Check the 'Sign the Assembly' option

e. Choose Browse option from the below dropdown as shown in below figure

Screenshot - sign_dll.jpg

f. A 'Select File' dialog box will appear. Go to the location where you have saved the strong name key and select the key.

g. Now Click on the Save button to save the setting.

7. Second step is to make the DLL Allow Partially Trusted.

8. Open the AssemblyInfo of the Project that you have strong named in the previous step.

Screenshot - partial_trusted.jpg

9. Add the below line in the AssemblyInfo file as shown above and Save the file

[assembly: System.Security.AllowPartiallyTrustedCallers]

10. Now Compile the project individually.

11. Go to the output folder of the project and take the DLL. This DLL is the one that is required to be used in the SharePoint site.

Now that we have got the Enterprise library DLL, then next step is to add the application block and the references to the SharePoint site. For this we need to do the following.

(Note: For this article, we add the DataAccess Application Block)

Adding Application Blocks into SharePoint site

1. Open your SharePoint site web.config (Usually in

C:\Inetpub\wwwroot\wss\VirtualDirectories\<Port No>\web.config)

2. Add the following in the <configSections> section Add the following in the <configSections> section

<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data" requirePermission="false" />

3. Add the following section right after the <ConfigSections> section

<dataConfiguration defaultDatabase="SampleDatabaseName" />

4. Add another section right after the previous section

<connectionStrings> <add name="SampleDatabaseName" connectionString="Data Source=<DataServerName>;Initial Catalog=<DatabaseName>;user=<DatabaseUserName>;pwd=<DatabasePassword>;Persist Security Info=true;" providerName="System.Data.SqlClient" /> </connectionStrings>

5. Put the Enterprise Library DLLs that your SharePoint site uses in the bin folder which is in the same location as your web.config file

6. Make the DLLs that you have added as Safe Controls by adding them in the <SafeControls> section

<SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Common" Namespace="Microsoft.Practices.EnterpriseLibrary.Common" TypeName="*" Safe="True" />

<SafeControl Assembly="Microsoft.Practices.EnterpriseLibrary.Data" Namespace="Microsoft.Practices.EnterpriseLibrary.Data" TypeName="*" Safe="True" />

<SafeControl Assembly="Microsoft.Practices.ObjectBuilder" Namespace="Microsoft.Practices.ObjectBuilder" TypeName="*" Safe="True" />

(The above DLLs are added for the Data Application block DLLs)

7. Change the level in the <trust> node to WSS_Medium

<trust level="WSS_Medium" originUrl="" />

8. Also add/uncomment the following line in the <PageParserPaths> section

<PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="true" IncludeSubFolders="true" />

Now your SharePoint site is ready to use the Data Access Application Block of Microsoft Enterprise Library.

Note: You now use the Enterprise Library Configuration tool to add other application blocks.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

srivatsan24
Architect
India India
I am a .NET/Sharepoint and Project Server Consultant. I hold Microsoft Technology Specialist certifications on ASP.NET 3.5 and Sharepoint 2007 Application Development

Comments and Discussions

 
QuestionCan we use enterprise library 5.0 in infopath form managed code?whether infopath will support enterprise library 5.0 Pinmemberphani1069514-Mar-11 1:25 
Questionun able to deploy infopath form in sharepoint using enterprise library 5.0 Pinmemberphani1069514-Mar-11 0:38 
GeneralCaching Application Block Pinmemberbaji.md19-Apr-09 21:37 
Generalsalam Pinmembersaber1381200227-Dec-08 20:16 
GeneralNo item exists error when I click edit link in DataView PinmemberTripathi Swati6-Aug-08 3:58 
QuestionWhat if i m having only DLL's [modified] PinmemberTripathi Swati30-Jul-08 2:56 
AnswerRe: What if i m having only DLL's Pinmembersrivatsan246-Aug-08 3:47 
GeneralRe: What if i m having only DLL's PinmemberTripathi Swati6-Aug-08 3:53 
GeneralSharePoint Pinmembersilpakirans@gmail.com16-Jul-08 23:03 
GeneralRe: SharePoint Pinmembersrivatsan2412-Aug-08 20:55 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Nov 2007
Article Copyright 2007 by srivatsan24
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid