By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,994 Members | 2,073 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,994 IT Pros & Developers. It's quick & easy.

Ready class for accessing configuration file

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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 fond 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

P: n/a
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 fond 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.