Click here to Skip to main content
1,133 members
Articles / AMD / Visual Studio 2005
Posted 25 Nov 2011



Using Microsoft Enterprise Library Application Block in SharePoint

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
25 Nov 2011CPOL
This article will tell how to use Microsoft Enterprise Library Application blocks in a Sharepoint site

This article is a sponsored article. Articles such as these are intended to provide you with information on products and services that we consider useful and of value to developers


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)


About the Author

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

-- There are no messages in this forum --