Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...This site is truly a marvel. Without a doubt the most comprehensive, friendly and just plain useful resource of its kind..."

Geography

Where in the world do Tek-Tips members come from?

set an class's app.config values in a web.confg

ralphtrent (Programmer)
8 Jun 12 10:19
I have been searching all morning but nothing seems to be what I need to do.

I have a class that will create an Excel workbook. I need to have some settings set at run time; client id etc. etc. etc. I initially wrote this all in an exe but need to not give it a web-presence.

I need to keep the settings in the class, which I have but I need to make the settings exposed to the front end.

I know I can make the settings settable as well as read only and I have done that and I was able to modify the value of the client id in code, but there are some settings, that I would like to change via the web.config file.

I have added this to my web.config. The name of my class is TzRptClientDefectsCls.

CODE

<configSections> <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" > <section name="TzRptClientDefectsCls.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </sectionGroup> </configSections>

I then added this

CODE

<appSettings> <TzRptClientDefectsCls.Settings> <setting name="ClientId" serializeAs="System.Int32"> <value>666</value> </setting> </TzRptClientDefectsCls.Settings> </appSettings>

Do I need to do anything else to be my setting valued? Do I need to explicitly set the value of my ClientId?

Any help is appreciated.
jbenson001 (Programmer)
8 Jun 12 10:55
I have never seen anything done like you are doing in your web.config. I tried your code, but it gives me errors (in 4.0).

Anyway, I am confused by your post. What do you want to do? You have a class named TzRptClientDefectsCls. Now what do you want to do? Do you want to set properties in the class by reading your web.config file?
ralphtrent (Programmer)
8 Jun 12 11:00
Yes that is what I am trying to do.

I got that idea i posted above from here:
Link
jbenson001 (Programmer)
8 Jun 12 11:11
I think in that post, the poster had multiple app.config files and was in different assemblies and was trying to access values in one app config from a different assembly(.exe)

In your case, if you just have one project/web and one web.config, then it is easy. You just access the value as you would any other.

<appSettings>
<add key="ClientID" value="12345"/>
</appSettings>

In code:

CODE

TzRptClientDefectCls.ClientID = ConfigurationManager.AppSettings["ClientID "];

Or is your class compiled in it's own exe/assembly and you are trying to write to it?
ralphtrent (Programmer)
8 Jun 12 11:16
It is in its own assembly.

I can do what you suggest by making the setting "settable" but i was hoping to not have to explicitly set it in code as well as create a web.config setting. I was hoping to only make a web.config setting and then that have data feed to my assembly automatically. Not sure if that is even possible.
jbenson001 (Programmer)
8 Jun 12 11:17
I have never had the need to do this. Quite and interesting issue.
Did you follow the link in the article you posted? Someone wrote something that may help you:
http://www.codeproject.com/Articles/246201/Settings-in-an-assembly-configuration-file
ralphtrent (Programmer)
8 Jun 12 11:21
hmm i must have overlooked that. Ill check it out. Thanks
jbenson001 (Programmer)
8 Jun 12 11:28
Sure. Let me know how it goes. I am curious to know if this works.
ralphtrent (Programmer)
8 Jun 12 13:12
I tested that out and it looks like what that was doing is already in 4.0. All that does it lets your settings be read externally via code. I was able to do that, I need to set the values. I guess I will need to expose some public methods to do so in my class and then have generic web.config app settings that will hold my values and then read them into my public methods.

It just seems like something like this would be a common issue. To have a comman dll, serve multiple mediumns.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close