473,396 Members | 1,918 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,396 software developers and data experts.

Ready class for accessing configuration file

Dear all,

Does any one have a ready class that is able to access a
configuration file and make different type of querry,
read, write operation?

Why re invanting the real if something already exist and
as we share things in usegroup in general...

thanks for your help
Jul 19 '05 #1
6 2319
Elp
Hi,
Does any one have a ready class that is able to access a
configuration file and make different type of querry,
read, write operation?


If you mean a custom user setting file for your application, you can find
plenty of them on the web. Just a few examples (look through the article to
find the section related to the setting file):
http://www.msdnaa.net/Resources/display.aspx?ResID=1929 (very easy to
understand and reuse, using the IsolatedStorage class)
http://www.msdnaa.net/Resources/display.aspx?ResID=1975 (idem but without
using IsolatedStorage)
or http://www.codeproject.com/useritems...asp#xx385470xx
also : http://www.codeproject.com/csharp/app_config.asp
You may also want to use the MS application configuration block :
http://msdn.microsoft.com/library/de.../html/cmab.asp

bye
mehdi
Jul 19 '05 #2
Thnaks for your links

By the way what do u suggest to use ?
- configuration management block
- XML documents function

Thnaks for your answer
-----Original Message-----
Hi,
Does any one have a ready class that is able to access a
configuration file and make different type of querry,
read, write operation?
If you mean a custom user setting file for your

application, you can findplenty of them on the web. Just a few examples (look through the article tofind the section related to the setting file):
http://www.msdnaa.net/Resources/display.aspx?ResID=1929 (very easy tounderstand and reuse, using the IsolatedStorage class)
http://www.msdnaa.net/Resources/display.aspx?ResID=1975 (idem but withoutusing IsolatedStorage)
or http://www.codeproject.com/useritems...nager.asp#xx38
5470xxalso : http://www.codeproject.com/csharp/app_config.asp
You may also want to use the MS application configuration block :http://msdn.microsoft.com/library/default.asp? url=/library/en-us/dnbda/html/cmab.asp
bye
mehdi
.

Jul 19 '05 #3
Elp

"serge calderara" <se*************@maillefer.net> wrote in message
news:04****************************@phx.gbl...
Thnaks for your links

By the way what do u suggest to use ?
- configuration management block
- XML documents function


i've still not implemented the setting management in my application (i'm
gonna do that today actually) but i think that i will go for the solution
exposed in the first link i gave you. It looks easy and clear enough for me
(and the setting file is automaticaly stored in a safe place thanks to the
IsolatedStorage system). I had a quick look at the MS configuration
management block but it looked more heavy to understand and use and it
requires 1.1 which i don't use now.

good luck.
Jul 19 '05 #4

Hi,

But this StoreIolate seems a bit different no?
it seems that it collect information of the current user,like
environement settings ...

But where this file is located when it creates it, is it pure memory or
what ? could not foînd it

SOund more complex that andling pure aaplication.config file with
XMLDocuments no?

Or maybe I did not really catch the purpopse of this Isolate stuff, in
my case I need just to create, even manually, a file with different
parameters in that my application will use

thnaks for your commnents
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #5
Elp

"calderara serge" <se*************@maillefer.net> wrote in message
news:Oq**************@tk2msftngp13.phx.gbl...

Hi,
Hi,
But this StoreIolate seems a bit different no?
it seems that it collect information of the current user,like
environement settings ...

But where this file is located when it creates it, is it pure memory or
what ? could not foînd it
i've implemented my configuration management yesterday and it's working well
so far. I used the first link i gave you in my first message. I had to
modify a bit the code to make it actually work. I use IsolatedStorage to get
the path where i can store my setting file and an XML serializer to actually
create the file. It gives me an XML file which contains all my user
settings.

IsolatedStorage is only a way to get a path where you can store your setting
file (or whatever else related to your application). If you use that,
instead of manually indicate a path on the hard drive, you ensure that:
- the user running the application has read/write access to that path, you
don't have to bother of which operating system he is running and/or which
access rights he has
- the path given to you by IsolatedStorage is unique to your assembly and/or
domain, which means that even if an other application installed on the same
machine uses the same name than yours for its setting file, you won't
overwrite its setting file by mistake.

For example, for my application, the setting file is stored in :
C:\Documents and Settings\USER\Local Settings\Application
Data\IsolatedStorage\biif0gen.lgz\4iywbas3.5tz\Url .etsikv0grd1xsubxhp2n5bfdz
aioaiuu\Url.etsikv0grd1xsubxhp2n5bfdzaioaiuu\Files
SOund more complex that andling pure aaplication.config file with
XMLDocuments no?


this is actually pure XML application config file. And simply generated by
an XML serializer.

Here is how i do it (it is a modified version of the code found in the link
i gave you, in c#, sorry if you are using VB) :
- first you need to create a small class which will contain all your user
settings. This class is going to be serialized into the XML file :
//class containing all the settings and serialized into a file

[Serializable()]

public class ConfigurationData

{

//all user settings, you may want to make those fields private and use
public properties to get/set their values

public string m_userName = null;

public string m_pet = null;

//constructors

public ConfigurationData() {}

public ConfigurationData(string userName, string pet)

{

m_userName = userName;

m_pet = pet;

}

}

- and here is how you can store your settings into an XML file:
private static void saveSettings(string userName, string pet)

{

//name of the setting file

string settingFileName = "setting.xml";

//the actual user settings

ConfigurationData settings = new ConfigurationData(userName, pet);

try

{

//folder containing the setting file, unique for that application

IsolatedStorageFile isolatedStore =
IsolatedStorageFile.GetUserStoreForDomain();

XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationData));

IsolatedStorageFileStream stream = new
IsolatedStorageFileStream(settingFileName ,

System.IO.FileMode.Create,

System.IO.FileAccess.ReadWrite,

isolatedStore);

//we write the file

serializer.Serialize(stream, settings);

stream.Close();

}

catch (Exception error)

{

MessageBox.Show("Error while saving settings : " + error.Message);

}

}
- and now, here is how you can read that setting file

private static ConfiguarationData loadSettings()

{

//name of the setting file

string settingFileName = "setting.xml";

//user settings

ConfigurationData settings = null;

//folder containing the setting file

IsolatedStorageFile isolatedStore;
isolatedStore = IsolatedStorageFile.GetUserStoreForDomain();

//we check if a setting file is already there

if (isolatedStore.GetFileNames(m_settingFileName).Len gth > 0)

{

try

{

//we retrieve the values from this setting file

XmlSerializer serializer = new XmlSerializer(typeof(ConfigurationData));

IsolatedStorageFileStream stream = new IsolatedStorageFileStream

(settingFileName,

System.IO.FileMode.Open,

System.IO.FileAccess.Read,

isolatedStore);

settings = (ConfigurationData)(serializer.Deserialize(stream) );

stream.Close();

}

catch (Exception error)

{

MessageBox.Show("Error while reading setting file : " + error.Message);

//let's create a default set of user settings

settings = new ConfigurationData("default name", "default pet");

}

}

else

{

//no setting file is present, create a default set of user settings

settings = new ConfigurationData("default name", "default pet");

}

return settings;

}
Jul 19 '05 #6
Thnaks for your example.

Sounds to be a bit different that a normal application configuration
file because as far as I understand you generate the configuration file
manually by specifying your own section and settings for your
application and then read or write into that file for corresponding
value.

In your sample you define trough code your all configuration needs and
then create the configuration file base on that right?

What SERIALIZE keyword means at the begining of your class?

Does you final xmlk file will be with the form App.exe.config ? this is
the name of the file I reada it has to be

regards
serge

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #7

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

Similar topics

26
by: Simon | last post by:
I'm doing a survey. When do you think GNU/Linux will be ready for the average Joe? What obstacles must it overcome first?
2
by: wan2tri | last post by:
hello, good day to all of you, hi, im am new in .net , how can i access two or more object remotely , because currently im only accessing one object, windows services is the host, i have a...
10
by: Not Available | last post by:
On the host server: namespace JCart.Common public class JCartConfiguration : IConfigurationSectionHandler private static String dbConnectionString; public static String ConnectionString { get...
0
by: Joergen Bech | last post by:
Fairly new to ASP.NET 1.1. Getting the error below when running application on a web server outside of my control, but only the first time I run it: 1. After a long period of inactivity (or...
6
by: Serge calderara | last post by:
Dear all, Does any one have a ready class that is able to access a configuration file and make different type of querry, read, write operation? Why re invanting the real if something already...
1
by: muthu | last post by:
Hi guys, Iam using dot framework 2.0.vs.net2005.I created a class library project and added a class file.And also i added a app.config file.And i declared a connection string in that config...
0
by: metaperl | last post by:
A Comparison of Python Class Objects and Init Files for Program Configuration ============================================================================= Terrence Brannon bauhaus@metaperl.com...
2
by: mma | last post by:
hello everyone, i have a solution that contains the following project types: 1. Class library contains a singleton class that handles the data access (sql server 2005). 2. Windows service....
16
by: Robert Dufour | last post by:
Here's the class code snippet Imports System.Configuration.ConfigurationManager Public Class Class1 Public _strTestSetting As String Public Sub SetTestsetting()
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.