473,761 Members | 1,808 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Getting settings values in an assermbly library from an ASP.NET or Winform

WT
Hello,

Using VS2005.
I have an assembly library that can be called from a Web site asp.net
application or from a winform application.
From this library I need to retrieve a path using simply a key like
'libPath'.
As far as winform and asp.net share the same common base class for settings,
SettingsBase, how to manage this ?
For winform the value should be set in app.config and for web site in
web.config.
I am looking for some sample ?

Any help welcome.

CS
Jan 23 '07 #1
6 2809
Hi,

Web:

- Application Settings (settings must be added to the web.config manually)
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx
- 2.0 Provider framework
- Proprietary file
- Database
- Registry
- WebConfiguratio nManager
http://msdn2.microsoft.com/en-us/lib...onmanager.aspx

Non-web:

- Application Settings (settings must be added to the app.config manually)
[same link as for web]
- 2.0 Provider framework
- Proprietary file
- Database
- Registry
- ConfigurationMa nager
http://msdn2.microsoft.com/en-us/lib...onmanager.aspx

I'm sure there's more choices that I haven't thought of so this is probably
not an exhaustive list.

Check if HttpContext.Cur rent and if it's not null then it's a web
application. Otherwise, it's not a web application. With this information
you may want to change how and where the settings are persisted for your
class library, especially if security is a concern.

From the information you have provided it sounds like Application Settings
may be your best bet since it's easy to use and should work for both
applications, and it seems that you're trying to go that route already.
Copy the settings created by the default settings in your class library
project from the dll's configuration file into the app.config or the
web.config and they should work. Make sure you choose settings names that
won't conflict with other settings in the actual application.

--
Dave Sexton
http://davesexton.com/blog

"WT" <WT@newsgroups. nospamwrote in message
news:u0******** ******@TK2MSFTN GP02.phx.gbl...
Hello,

Using VS2005.
I have an assembly library that can be called from a Web site asp.net
application or from a winform application.
From this library I need to retrieve a path using simply a key like
'libPath'.
As far as winform and asp.net share the same common base class for
settings, SettingsBase, how to manage this ?
For winform the value should be set in app.config and for web site in
web.config.
I am looking for some sample ?

Any help welcome.

CS

Jan 23 '07 #2
WT
Thanks,

MS has to do a last step to avoid us testing HttpContext.Cur rent... :)
CS
"Dave Sexton" <dave@jwa[remove.this]online.coma écrit dans le message de
news: OS************* *@TK2MSFTNGP06. phx.gbl...
Hi,

Web:

- Application Settings (settings must be added to the web.config manually)
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx
- 2.0 Provider framework
- Proprietary file
- Database
- Registry
- WebConfiguratio nManager
http://msdn2.microsoft.com/en-us/lib...onmanager.aspx

Non-web:

- Application Settings (settings must be added to the app.config manually)
[same link as for web]
- 2.0 Provider framework
- Proprietary file
- Database
- Registry
- ConfigurationMa nager
http://msdn2.microsoft.com/en-us/lib...onmanager.aspx

I'm sure there's more choices that I haven't thought of so this is
probably not an exhaustive list.

Check if HttpContext.Cur rent and if it's not null then it's a web
application. Otherwise, it's not a web application. With this
information you may want to change how and where the settings are
persisted for your class library, especially if security is a concern.

From the information you have provided it sounds like Application Settings
may be your best bet since it's easy to use and should work for both
applications, and it seems that you're trying to go that route already.
Copy the settings created by the default settings in your class library
project from the dll's configuration file into the app.config or the
web.config and they should work. Make sure you choose settings names that
won't conflict with other settings in the actual application.

--
Dave Sexton
http://davesexton.com/blog

"WT" <WT@newsgroups. nospamwrote in message
news:u0******** ******@TK2MSFTN GP02.phx.gbl...
>Hello,

Using VS2005.
I have an assembly library that can be called from a Web site asp.net
application or from a winform application.
From this library I need to retrieve a path using simply a key like
'libPath'.
As far as winform and asp.net share the same common base class for
settings, SettingsBase, how to manage this ?
For winform the value should be set in app.config and for web site in
web.config.
I am looking for some sample ?

Any help welcome.

CS


Jan 23 '07 #3
Hi CS,

To use a class library which has its own configurations either in a WinForm
application or a Web application, since .NET can only load a default
configuration file per AppDomain (which is by default the .exe.config with
the executing assembly), the dll cannot have separate complete
configuration file for it. However, using an optional attribute named
"configSour ce" for the confugration file's section elements, we could put
some configuration sections in a separate config file, this will prevent
copying/merging large parts of the configuration data, only the
configSource attribute is needed to modify.
=============== =========
General Attributes Inherited by Section Elements
http://msdn2.microsoft.com/en-us/library/ms228167.aspx

configSource
Optional String attribute.

Specifies the name of the include file in which the associated
configuration section is defined, if such a file exists. Programmaticall y
accessible through the ConfigSource property.
=============== =========

Here's some usage scenario:

1) Create a Class Library named "ClassLibrary1" , use the Settings Designer
to add some application-wide settings into it.
2) Open app.config, it will roughly have following content:
<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<sectionGroup name="applicati onSettings"
type="System.Co nfiguration.App licationSetting sGroup, System,
Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="ClassLibr ary1.Properties .Settings"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" requirePermissi on="false"
/>
</sectionGroup>
</configSections>
<applicationSet tings>
<ClassLibrary1. Properties.Sett ings>
<setting name="libPath" serializeAs="St ring">
<value>d:\tem p</value>
</setting>
</ClassLibrary1.P roperties.Setti ngs>
</applicationSett ings>
</configuration>
3) Create a new xml file, named it as "ClassLibrary1. dll.settings.co nfig",
copy the inner content of the <applicationSet tingstag to this file:

<ClassLibrary1. Properties.Sett ings>
<setting name="libPath" serializeAs="St ring">
<value>d:\tem p</value>
</setting>
</ClassLibrary1.P roperties.Setti ngs>
4) Modify app.config: remove the inner content of the tag
<ClassLibrary1. Properties.Sett ings>, add an attribute "configSour ce" to it
as:

<applicationSet tings>
<ClassLibrary1. Properties.Sett ings
configSource="C lassLibrary1.dl l.settings.conf ig">
</ClassLibrary1.P roperties.Setti ngs>
</applicationSett ings>

5) Note the Settings Designer will still work correctly, modifying settings
will reflect changes to the separate file
"ClassLibrary1. dll.settings.co nfig" instead of the App.Config.

6) For test purpose, create a static property in one public class in this
class library to return the setting "libPath".

7) Now create a winform/console/web application, reference the class
library, modify this application's app.config or web.config to modify the
<configSections part as:

<configSections >
<sectionGroup name="applicati onSettings"
type="System.Co nfiguration.App licationSetting sGroup, System,
Version=2.0.0.0 , Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="ClassLibr ary1.Properties .Settings"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" requirePermissi on="false"
/>
</sectionGroup>
</configSections>
<applicationSet tings>
<ClassLibrary1. Properties.Sett ings
configSource="C lassLibrary1.dl l.settings.conf ig">
</ClassLibrary1.P roperties.Setti ngs>
</applicationSett ings>

8) Copy the ClassLibrary1.d ll.settings.con fig from the class library
project to this project. If this is the web project, just copy to the same
directory with web.config; otherwise, make sure you set its "Copy to output
directory" property to "Copy always".

9) Now calls into the class library's static property defined in step 6),
change the local 'ClassLibrary1. dll.settings.co nfig', it should reflect
updated value.
Hope this helps. Let me know if there's anything unclear.
Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 24 '07 #4
Please note I haven't fully tested this approach, though it seems working
on my side using a simple web site and a simple console application. If you
do find any issues, please feel free to let me know.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Jan 24 '07 #5
WT
I will try it, seems good solution.
More later, thanks.
CS
"Walter Wang [MSFT]" <wa****@online. microsoft.coma écrit dans le message
de news: 0a************* *@TK2MSFTNGHUB0 2.phx.gbl...
Please note I haven't fully tested this approach, though it seems working
on my side using a simple web site and a simple console application. If
you
do find any issues, please feel free to let me know.

Regards,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no
rights.

Jan 25 '07 #6
For me this fails to work since it only picks up default values and
not stuff from the config file.

Regards
Lars Schouw

Mar 2 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
4140
by: Aniket Sule | last post by:
Hi, Is there a way to read Component Services /IIS settings values using c# ? I am specifically interested in the COM Transaction timeout value and the IIS connection timeout value. Are these in any Registry keys or config files that I can read ? Thanks in advance Aniket
2
2022
by: Ben Dewey | last post by:
Hey, I have kind of an architecture question. I have a dynamic website that is using a Windows Form Backend and a ASP.NET front end. They are both using C# 2.0. I also have a class library that contains namespaces for Com.Site and Com.Site.Data. Com.Site contains my business objects which, for security reasons only contains a return GetList List<obj>, maybe a Search.
10
6928
by: Dan | last post by:
I use the settings grid to create a setting named "ServerName". Now i want to retrieve it in code and i can't figure out how. This should be incredibly obvious but i cant get it. I have tried creating an AppSettingsReader and using GetValue("ServerName", typeof(String)). That threw an error about key not found. Then i tried ConfigurationManager.AppSettings but that returns blank. I supplied a value when i created the setting. I...
2
1487
by: sobmir | last post by:
A I'm new to c# and I came from c++ also. I want to create dynamicaly winform to get some data. I create a array of object as a description of variable which I want to get. I pass this array to a function which build a form, show the edit fields and return changed values. Changed values are stored in my array of objects but these original values are not changed. Short code snipet ( this is working) // ---- c# ---- struct desc {
1
1513
by: Brett Romero | last post by:
I've created a new settings file named AppList.settings for a Winform app. In the Program.cs file, I can access values in settings.settings fine. However, when I do this: SettingsPropertyValueCollection propertyColl = MyNameSpace.Properties.AppList.Default.PropertyValues; No values come back; the collection is empty. There are three entries in the file. However, if I set a breakpoint anywhere in the Program.cs file, I get values...
4
2645
by: Richard Lewis Haggard | last post by:
I have an application that can't use the registry to save various user options and application settings. My first thought was to simply use an application configuration file but this approach seems flawed. The app config file appears to be updated with values while the application is running but when the application closes, the file seems to get restored to a pristine state and the accumulated user options and application settings are...
13
7145
by: Dave | last post by:
When using the properties designer to store application wide properties how do you get this to work across a project group containing an EXE and a collection of DLLs. I'm using C#.Net 2005. I noticed that the designer creates and app.config that gets copied to the output directory as a .exe.config or .dll.config. In this setup any Application Scope property that is in the .exe.config file can be read in from the file and used. My...
11
10150
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I have worked with application settings in VS2005 and C# for awhile, but usually with standard types. I have been trying to store a custom container/class/type in an application setting and I have seen erratic results. I am aware of one known defect where user classes do not show up in the list of types on the Property/Settings page in the visual designer and I am wondering if I am encountering some other peculiar issue, or if there are...
3
1057
by: John | last post by:
Hi Is there a way to have application settings in asp apps, like those in winform apps? Thanks Regards
0
9554
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9377
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9989
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9925
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6640
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5405
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.