Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

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

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
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.
 
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?
 
Yes that is what I am trying to do.

I got that idea i posted above from here:
Link
 
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?
 
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.
 
hmm i must have overlooked that. Ill check it out. Thanks
 
Sure. Let me know how it goes. I am curious to know if this works.
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top