rutlean

Is it possible for two or three different projects to use the same settings file If one project is ran and makes changes to the settings file, will the changes show up when the next project is ran

Thanks


Re: Visual C# General Settings File Question

OmegaMan

Just to be clear, which settings file are you talking about Is this the app.config or a specific file created by Visual Studio





Re: Visual C# General Settings File Question

Peter Ritchie

No, the app.config must be in the same directory as the project and the Settings.Settings file is generated by the IDE and needs to match the generated code in the project for it.






Re: Visual C# General Settings File Question

ARK88

If the settings you are referring to are in app.config, there is an extra attribute you can add to that file to reference a secondary configuration file that is in another [relative] location. This attribute causes information from the secondary file to be merged with the current file. I did this once to allow me to have a single settings (app.config) file in a centralized location (a network share) so that if any of the settings changed I didn't have to go update x-number of settings files located on x-number of computers. Your application code doesn't need to change with this approach, as the merging is handled automatically.

You can look this up in the help file to see if it is what you want/need. The basic syntax is as follows:

Main application app.config:
< xml version="1.0" encoding="utf-8" >
<configuration>
<appSettings file="Secondary.Global.config">
<add key="MyKey" value="MyValue"/>
</appSettings>
</configuration>


Secondary configuration file:
< xml version="1.0" encoding="utf-8" >
<appSettings>
<add key="MyOtherKey" value="MyOtherValue"/>
</appSettings>


...ends up creating a file configuration file (at runtime) that looks like this to your application:

< xml version="1.0" encoding="utf-8" >
<configuration>
<appSettings>
<add key="MyKey" value="MyValue"/>
<add key="MyOtherKey" value="MyOtherValue"/>
</appSettings>
</configuration>





Re: Visual C# General Settings File Question

boban.s

You will need to create xml configuration file in order to have one common setting file. But i think that this can be avoided as a need if you change your application's design. What i mean by that is that if you need some common thing, then that could be placed in separate library that will be used by both applications. Again you will have xml configuration file. I will describe it in a scenario.
Imagine you have data access layer which needs connection settings. If you place this data layer that needs that connection properties in applications, which both use same connection, than solution is to move all source for data layer in separate assembly and both applications will use same assembly for accessing database, using same connection properties. And it's common way of storring assembly configurable variables in xml config file.






Re: Visual C# General Settings File Question

rutlean

What I am actually doing is saving a meter address and a com port. One application is the configurator, it sets the meter address and the com port number. The second application is a calibrator tool that communicates with a motion controller through the saved com port number and communicates with HP Voltage meter through the HPIB address that was saved as well.

It sounds like the xml is the way to go. Will both applications be able to read and write to the file

Thanks for the info.

Andy




Re: Visual C# General Settings File Question

boban.s

rutlean wrote:
What I am actually doing is saving a meter address and a com port. One application is the configurator, it sets the meter address and the com port number. The second application is a calibrator tool that communicates with a motion controller through the saved com port number and communicates with HP Voltage meter through the HPIB address that was saved as well.

It sounds like the xml is the way to go. Will both applications be able to read and write to the file

Thanks for the info.

Andy


Yes, you can change xml file, from anywhere you like.
If you use typed dataset, you can access properties in xml file in typed way, simular as with application settings.






Re: Visual C# General Settings File Question

rutlean

I am new to creating a XML application file. What is the best way to create one Is it generated like the settings files inside the project properties page

Thanks




Re: Visual C# General Settings File Question

OmegaMan

rutlean wrote:
I am new to creating a XML application file.&nbsp; What is the best way to create one &nbsp; Is it generated like the settings files inside the project properties page <br><br>Thanks<br>
Yes, but see Using Settings in C# for more info.




Re: Visual C# General Settings File Question

Peter Ritchie

I assume you me app.config by "XML Application file". The easiest way is to add one to your project. Right click your project in Solution Explorer and select "Add\New Item", then double-click the "Application Configuration File" Icon.