Use AppSettings and ConnectionStrings from a Web.config into a C# class library

Posted: May 30, 2008 in C#
Tags: ,

Well, you can use AppSettings and ConnectionStrings from a Web.config file into your class library. You might be thinking why should I use these objects from a web.config where as I already have App.config file resides in a C# class library. Well, the reason is, you might face some requirements like you want to create General APIs from class library and that can be used in a Website in which you allow user to provide its connection string and some app settings that will be used by this APIs. In this case end user will provide its connection string and all other settings in web.config file of his website. (No doubt, you need to provide static names of “Keys” that this library is using, so that your application runs smooth)

Now comming to the point; you can access AppSettings and ConnectionStrings objects by adding reference of System.Configuration.dll from .NET framework into your C# library Reference and include that namespace in your class file at the beggening like:

using System.Configuration;

Whether you found this article useful or not? please provide your valuable comments.

Advertisements
Comments
  1. Ecko says:

    thanks for sharing,,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s