473,324 Members | 2,456 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

how to share settings between app <-> class lib?

Hello NG,

Is it possible to share the settings of an application with a class
libreary?
In my case I have a application and a set of different reports (home made)
put into a class library.
The plan is to delivere different report.dlls with the main app.

But it is essentially importent, that the reports and the app use the same
settings.
How can I achieve this?

Thanks for help and hints.

Rainer Queck
Mar 6 '07 #1
5 8573

You can look here for an idea:
http://www.eggheadcafe.com/forums/Fo...=85647&INTID=6

...

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
Hello NG,

Is it possible to share the settings of an application with a class
libreary?
In my case I have a application and a set of different reports (home made)
put into a class library.
The plan is to delivere different report.dlls with the main app.

But it is essentially importent, that the reports and the app use the same
settings.
How can I achieve this?

Thanks for help and hints.

Rainer Queck


Mar 6 '07 #2
Hi Sloan,

thanks for the hint, but can't I just "pass on" my applications
Properties.Settings somehow?

Regards
Rainer

"sloan" <sl***@ipass.netschrieb im Newsbeitrag
news:Ou**************@TK2MSFTNGP05.phx.gbl...
>
You can look here for an idea:
http://www.eggheadcafe.com/forums/Fo...=85647&INTID=6

..

"Rainer Queck" <Ra****@noemail.noemailwrote in message
news:%2******************@TK2MSFTNGP05.phx.gbl...
>Hello NG,

Is it possible to share the settings of an application with a class
libreary?
In my case I have a application and a set of different reports (home
made)
put into a class library.
The plan is to delivere different report.dlls with the main app.

But it is essentially importent, that the reports and the app use the
same
settings.
How can I achieve this?

Thanks for help and hints.

Rainer Queck



Mar 6 '07 #3
Hi Rainer,

You will have two options:

Option A: Use SettingsGroupNameAttribute to specify a section name in your
class library, so that it could use the same settings section in your
application config (which is also used by your application):

1) In your class library, create the settings as usual; you could then use
strong-typed Settings.Default.<Keyto access those settings.

2) Create another separate class:

namespace ClassLibrary1.Properties
{
[SettingsGroupName("ConsoleApplication1.Properties. Settings")]
internal sealed partial class Settings :
global::System.Configuration.ApplicationSettingsBa se
{
}
}

(You need to add reference to System.Configuration.dll)

Please note this "ConsoleApplication1.Properties.Settings" can be modified,
just remember to use the settings section name in the application config
file (see below).

Also, the namespace should be same to the designer generated
Settings.Design.cs.

3) In your application, also use the settings designer to create those
settings (or simply copy over the content from app.config). Open the
app.config, you will see the

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConsoleApplication1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ConsoleApplication1.Properties.Settings>
<setting name="Key1" serializeAs="String">
<value>ConsoleApplication1</value>
</setting>
</ConsoleApplication1.Properties.Settings>
</applicationSettings>

If you changed the section name "ConsoleApplication1.Properties.Settings",
make sure you also modify them here.

4) Now reference the class library from the application, the class library
now will use the application's settings as well.
Option B: use "configSource" attribute of config section to move both the
class library and the application's settings into a separate settings file:

1) Create the settings in the class library as usual, add some settings;
then open app.config, copy the settings section
"ClassLibrary1.Properties.Settings" and save it into a separate file, for
example "SharedSettings.xml":

<ClassLibrary1.Properties.Settings>
<setting name="Key1" serializeAs="String">
<value>ClassLibrary1</value>
</setting>
</ClassLibrary1.Properties.Settings>

Modify the app.config to remove the content of the settings section and add
"configSource" attribute to point it to the external file
"SharedSettings.xml":

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ClassLibrary1.Properties.Settings
configSource="SharedSettings.xml">
</ClassLibrary1.Properties.Settings>
</applicationSettings>

2) In your application's config file, also point its settings section to
use this file:

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConsoleApplication2.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ConsoleApplication2.Properties.Settings
configSource="SharedSettings.xml">
</ConsoleApplication2.Properties.Settings>
</applicationSettings>

3) Copy the SharedSettings.xml from the class library to your application
directory, make sure you set its "Copy to output directory" property to
"Copy always" in its properties window.

4) Now both your class library and your application are using the separate
settings xml file "SharedSettings.xml".

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.

Mar 7 '07 #4
HI Walter,

thank you very much for the detailed answer.
It enlarged my horizont on the subject.
But since I am a very lazzy person I decided to choose option C:

I defined a interface for all needed settings and implemented it into the
classes evolved plus a little class reading my settings in the application.

Interface :
public interface IReportSettingsInterface
{
string PdfReader { get; set; }
string PdfReaderArgs { get; set; }
string ReportPath { get; set; }
string SamplePath { get; set; }
string TemplatePathe { get; set; }
}

Class constructor in library:
public GbReport(IReportSettingsInterface settings)
{
reportSettings = settings;
...
}

Settings reader class in application:
public class ReportSettings : IReportSettingsInterface
{
private string pdfReader;
private string pdfReaderArgs;
private string reportPath;
private string samplePath;
private string templatePathe;

public ReportSettings()
{
pdfReader = Properties.Settings.Default.PdfReader;
pdfReaderArgs = Properties.Settings.Default.PdfReaderArgs;
reportPath = Properties.Settings.Default.ReportPath;
samplePath = Properties.Settings.Default.SamplePath;
templatePathe = Properties.Settings.Default.TemplatePathe;
}
....
<properties set get>
}

Class factory in my app, instantiating the classes in my library:
....
GbReport report = Activator.CreateInstance(reportClassType, new Object[] {
new ReportSettings()}) as GbReport;
....

Works nice in my app ;-)

Regards
Rainer
"Walter Wang [MSFT]" <wa****@online.microsoft.comschrieb im Newsbeitrag
news:KG**************@TK2MSFTNGHUB02.phx.gbl...
Hi Rainer,

You will have two options:

Option A: Use SettingsGroupNameAttribute to specify a section name in your
class library, so that it could use the same settings section in your
application config (which is also used by your application):

1) In your class library, create the settings as usual; you could then use
strong-typed Settings.Default.<Keyto access those settings.

2) Create another separate class:

namespace ClassLibrary1.Properties
{
[SettingsGroupName("ConsoleApplication1.Properties. Settings")]
internal sealed partial class Settings :
global::System.Configuration.ApplicationSettingsBa se
{
}
}

(You need to add reference to System.Configuration.dll)

Please note this "ConsoleApplication1.Properties.Settings" can be
modified,
just remember to use the settings section name in the application config
file (see below).

Also, the namespace should be same to the designer generated
Settings.Design.cs.

3) In your application, also use the settings designer to create those
settings (or simply copy over the content from app.config). Open the
app.config, you will see the

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConsoleApplication1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ConsoleApplication1.Properties.Settings>
<setting name="Key1" serializeAs="String">
<value>ConsoleApplication1</value>
</setting>
</ConsoleApplication1.Properties.Settings>
</applicationSettings>

If you changed the section name "ConsoleApplication1.Properties.Settings",
make sure you also modify them here.

4) Now reference the class library from the application, the class library
now will use the application's settings as well.
Option B: use "configSource" attribute of config section to move both the
class library and the application's settings into a separate settings
file:

1) Create the settings in the class library as usual, add some settings;
then open app.config, copy the settings section
"ClassLibrary1.Properties.Settings" and save it into a separate file, for
example "SharedSettings.xml":

<ClassLibrary1.Properties.Settings>
<setting name="Key1" serializeAs="String">
<value>ClassLibrary1</value>
</setting>
</ClassLibrary1.Properties.Settings>

Modify the app.config to remove the content of the settings section and
add
"configSource" attribute to point it to the external file
"SharedSettings.xml":

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ClassLibrary1.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ClassLibrary1.Properties.Settings
configSource="SharedSettings.xml">
</ClassLibrary1.Properties.Settings>
</applicationSettings>

2) In your application's config file, also point its settings section to
use this file:

<configSections>
<sectionGroup name="applicationSettings"
type="System.Configuration.ApplicationSettingsGrou p, System,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="ConsoleApplication2.Properties.Settings"
type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false"
/>
</sectionGroup>
</configSections>
<applicationSettings>
<ConsoleApplication2.Properties.Settings
configSource="SharedSettings.xml">
</ConsoleApplication2.Properties.Settings>
</applicationSettings>

3) Copy the SharedSettings.xml from the class library to your application
directory, make sure you set its "Copy to output directory" property to
"Copy always" in its properties window.

4) Now both your class library and your application are using the separate
settings xml file "SharedSettings.xml".

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.


Mar 7 '07 #5
Hi Rainer,

Thank you for sharing your experience here. I'm glad you've solved the
issue.

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.

Mar 7 '07 #6

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

Similar topics

2
by: dan | last post by:
I get an error when I'm trying to run my application from a share on a remote machine. It seems that it generates an error any try my app is going to use an library (even mscorlib) It's falling...
6
by: Salty Dog | last post by:
Code: <%Response.Buffer = False%> <HTML> <HEAD> <title>Printing</title> </HEAD> <BODY> <center> <% FilePath = "c:\WUTemp\441817810_receiver.txt"
2
by: JJA | last post by:
I have 2 web servers both running win server 2003 with iis 6.0. On my PROD server I have a virtual directory called CONV. It points to a folder on the C drive of this PROD server. On my TEST...
1
by: Martin | last post by:
Hi, How can I share config data between different web apps? If I have 2 sub apps, can they inherit the config of the parent app? Is this the best way to share config between different web...
0
by: 1Cajun | last post by:
I would like to share settings between two projects in the same solution. How do i do this?
6
by: tendim | last post by:
G'day group. Currently our organization us using VB6 based applications, and I am trying to push forward and migrate some of the smaller things to VB.NET, eventually migrating all applications...
2
by: Bill Fallon | last post by:
I have a VS2005 VB.Net windows form application deployed to a share drive. The windows explorer security permissions for this application (.exe) file is set for Everyone with List Folder/Read Data...
3
by: =?Utf-8?B?VGltb3Rp?= | last post by:
Can any one tell me about how i can share my Desktop VS settings match with the laptop settings.. So that both my systems will be of same configurations and don't have to find the difficulty...
0
by: GregInHouston2 | last post by:
I am attempting to access the files on a share on a server in my network so I can list the files there on an intranet web page. At this point, the share permissions and the NTFS permissions are...
4
by: MLH | last post by:
I tried this in a module... call lineinputthing("\\MLH\Shared Docs\Leads.txt","26MAY08Garages") The machine name is MLH. The share name is "Shared Docs". The file name is Leads.txt. But VBA...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.