Click here to Skip to main content
15,905,614 members
Articles / Programming Languages / C#

Using Microsoft Enterprise Library Application Block in SharePoint

Rate me:
Please Sign up or sign in to vote.
3.88/5 (11 votes)
21 Nov 2007CPOL4 min read 67.1K   307   32   14
This article will tell how to use Microsoft Enterprise Library Application blocks in a Sharepoint site


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.


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:

Patch 2554 for MSEL download link:


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


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.


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

Written By
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 Pin
phani1069514-Mar-11 0:25
phani1069514-Mar-11 0:25 
Questionun able to deploy infopath form in sharepoint using enterprise library 5.0 Pin
phani1069513-Mar-11 23:38
phani1069513-Mar-11 23:38 
GeneralCaching Application Block Pin
baji.md19-Apr-09 20:37
baji.md19-Apr-09 20:37 
Generalsalam Pin
saber1381200227-Dec-08 19:16
saber1381200227-Dec-08 19:16 
GeneralNo item exists error when I click edit link in DataView Pin
Tripathi Swati6-Aug-08 2:58
Tripathi Swati6-Aug-08 2:58 
QuestionWhat if i m having only DLL's [modified] Pin
Tripathi Swati30-Jul-08 1:56
Tripathi Swati30-Jul-08 1:56 
AnswerRe: What if i m having only DLL's Pin
srivatsan246-Aug-08 2:47
srivatsan246-Aug-08 2:47 
GeneralRe: What if i m having only DLL's Pin
Tripathi Swati6-Aug-08 2:53
Tripathi Swati6-Aug-08 2:53 
GeneralSharePoint Pin
silpakirans@gmail.com16-Jul-08 22:03
silpakirans@gmail.com16-Jul-08 22:03 
GeneralRe: SharePoint Pin
srivatsan2412-Aug-08 19:55
srivatsan2412-Aug-08 19:55 
GeneralHi Sri. Pin
Member 245269820-May-08 2:18
Member 245269820-May-08 2:18 
GeneralRe: Hi Sri. Pin
srivatsan246-Aug-08 2:50
srivatsan246-Aug-08 2:50 
GeneralExperience and a wishlist Pin
Magnus Salgo26-Nov-07 18:28
Magnus Salgo26-Nov-07 18:28 
Thanks for a good start.

It would be nice to share your experience was it useful and to what did you use it?

What parts did you use? Does it fit inside Sharepoints Architecture or is it just another odd friend visiting....

Caching Block inside a webpart good or bad?!?[^][^]

Exception Handling
having your own policy etc. does that follow Sharepoint way? Is there a best practise inside Sharepoint? WMI?!?! What should we as Sharepoint developers deliver?

Logging Application Block
Is this a good way of add logging?!?! A System Administrator with 50 Sites would he be hppy if we role out a webpart on 20 sites with this kind of logging or Exception handling...

I also would like to see some installing help lika a feature...

Magnus Sälgö
Sälgö Consulting AB, Sweden

GeneralRe: Experience and a wishlist Pin
srivatsan2426-Nov-07 20:06
srivatsan2426-Nov-07 20:06 

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

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