473,545 Members | 2,006 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Best way to Read/write user/machine setting configuration files

In the beginning we had Ini files.
Later we had registery files.
Now have xml files and our read-only myapp.config file.

My question now, is what is the best way to store and load user and machine
specific settings for a .NET program?
And what classes, or code do we have to do this in C#?

I don't think that using the myapp.config is the best choice to store since
the file might be read-only if the program is started from a CD ROM, or if
the user does not have enough rights in the "program files" folder. So the
"My documents" choice might be better, or the registery? But this might be
read-only too?
Nov 15 '05 #1
7 6567
In article <40************ **********@news .skynet.be>,
Ol**********@sk yscan.be says...
In the beginning we had Ini files.
Later we had registery files.
Now have xml files and our read-only myapp.config file.

My question now, is what is the best way to store and load user and machine
specific settings for a .NET program?
And what classes, or code do we have to do this in C#?

I don't think that using the myapp.config is the best choice to store since
the file might be read-only if the program is started from a CD ROM, or if
the user does not have enough rights in the "program files" folder. So the
"My documents" choice might be better, or the registery? But this might be
read-only too?


You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 15 '05 #2
> > In the beginning we had Ini files.
Later we had registery files.
Now have xml files and our read-only myapp.config file.

My question now, is what is the best way to store and load user and machine specific settings for a .NET program?
And what classes, or code do we have to do this in C#?

I don't think that using the myapp.config is the best choice to store since the file might be read-only if the program is started from a CD ROM, or if the user does not have enough rights in the "program files" folder. So the "My documents" choice might be better, or the registery? But this might be read-only too?


You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.

Well, this helps part of my problem.

The second problem is this serialization, because I want Myprogram v1.0
still be able to read Myprogram v1.5 settings and vice versa.
A lot of sollutions I found are not worth it since it somehow converts the
v1.0 to v1.5 and no way to return back. So I am stil looking into this to
find a elegant sollution.

But thanks for the tip!!! :-)
Nov 15 '05 #3
If serialization isnt the best way for you then how about just make your own
XML format and use XmlDocument.Loa d(string filename) and
XmlDocument.Sel ectSingleNode(x Path);

I do this for my config files, I use "Root.Node.Node .Key" to get that
functionlity of an ini file.

I can also encrypt this by storing as base 64 strings to a file and Loading,
decrypting and XmlDocument.Loa dXml(unencrypte dXmlstring);

Works best for me when a custom format is required and serialization isnt
working well.

<Ol**********@s kyscan.be> wrote in message
news:40******** *************@n ews.skynet.be.. .
In the beginning we had Ini files.
Later we had registery files.
Now have xml files and our read-only myapp.config file.

My question now, is what is the best way to store and load user and machine specific settings for a .NET program?
And what classes, or code do we have to do this in C#?

I don't think that using the myapp.config is the best choice to store since the file might be read-only if the program is started from a CD ROM,
or
if the user does not have enough rights in the "program files" folder. So the "My documents" choice might be better, or the registery? But this
might
be read-only too?


You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.

Well, this helps part of my problem.

The second problem is this serialization, because I want Myprogram v1.0
still be able to read Myprogram v1.5 settings and vice versa.
A lot of sollutions I found are not worth it since it somehow converts the
v1.0 to v1.5 and no way to return back. So I am stil looking into this to
find a elegant sollution.

But thanks for the tip!!! :-)

Nov 15 '05 #4
> If serialization isnt the best way for you then how about just make your
own
XML format and use XmlDocument.Loa d(string filename) and
XmlDocument.Sel ectSingleNode(x Path);

I do this for my config files, I use "Root.Node.Node .Key" to get that
functionlity of an ini file.

I can also encrypt this by storing as base 64 strings to a file and Loading, decrypting and XmlDocument.Loa dXml(unencrypte dXmlstring);

Works best for me when a custom format is required and serialization isnt
working well.

This was the idea I was looking into, originally I used ini files and
registery, but I might use xml now, since it has a lot of potential.
Nov 15 '05 #5
You can easily edit them with XMLNotepad (which you cant do if its
serialized it just complains), XMLNotepad is no longer supported though but
it works.

<Ol**********@s kyscan.be> wrote in message
news:40******** **************@ news.skynet.be. ..
If serialization isnt the best way for you then how about just make your

own
XML format and use XmlDocument.Loa d(string filename) and
XmlDocument.Sel ectSingleNode(x Path);

I do this for my config files, I use "Root.Node.Node .Key" to get that
functionlity of an ini file.

I can also encrypt this by storing as base 64 strings to a file and

Loading,
decrypting and XmlDocument.Loa dXml(unencrypte dXmlstring);

Works best for me when a custom format is required and serialization isnt working well.

This was the idea I was looking into, originally I used ini files and
registery, but I might use xml now, since it has a lot of potential.

Nov 15 '05 #6
In article <40************ *********@news. skynet.be>,
Ol**********@sk yscan.be says...
You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.

Well, this helps part of my problem.

The second problem is this serialization, because I want Myprogram v1.0
still be able to read Myprogram v1.5 settings and vice versa.
A lot of sollutions I found are not worth it since it somehow converts the
v1.0 to v1.5 and no way to return back. So I am stil looking into this to
find a elegant sollution.


You could implement the ISerializable interface and control
serialization/deserialization yourself. During serialization, you could
write out a version number. Likewise, during deserialization , you could
read this version number and make sure your current application supports
that version.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 15 '05 #7
> > > You could serialize a simple class to the users' application directory
(see the Environment.Spe cialFolder enumeration). To re-load those
settings, just de-serialize the file.

Well, this helps part of my problem.

The second problem is this serialization, because I want Myprogram v1.0
still be able to read Myprogram v1.5 settings and vice versa.
A lot of sollutions I found are not worth it since it somehow converts the v1.0 to v1.5 and no way to return back. So I am stil looking into this to find a elegant sollution.


You could implement the ISerializable interface and control
serialization/deserialization yourself. During serialization, you could
write out a version number. Likewise, during deserialization , you could
read this version number and make sure your current application supports
that version.


For the moment I am using the xml direction (XmlDocument).
At first I thought this was something like ini files, just a little bit more
nestend then it turns out that it is far advanced, it is close to a
database.

I had some small problem with reloading the file an add things to it without
losing the other unknown information.
I wanted a program v1.0 to read a v2.0 xml configuration file, and save the
settings whie it stays a v2.0 xml file, thus the v2.0 program still have all
it's configuration available. Only when I see that some nodes are missing, I
add them.

It took me some time to realize that mXmlDocument.Se lectSingleNode( ) has
some SQL-like (actually XPath) syntax.
So mLastUsedNode=m XmlDocument.Sel ectSingleNode(" LastUsed"; always returned
null,
I had to use
mLastUsedNode=m XmlDocument.Sel ectSingleNode(" descendant::Las tUsed") instead.
(see code sampple)

--------------------------
mLastUsedNode=m XmlDocument.Sel ectSingleNode(" descendant::Las tUsed");
if (mLastUsedNode= =null ) {

mLastUsedNode=m Configuration.A ppendChild(mXml Document.Create Element("LastUs e
d"));
}
----------------------

One other thing that I now realize is to filter the characters that you re
going to save. Filling in a string "<blabla" might crash the xml.
The same typical problems SQL databases have.

The xml direction is a good direction what I want to do.
Only the stability scares me a little, it is as unstable as other database
engines.
e.g. I open the xml file with notepad, an it crashes my explorer.
Other example is something like this:
mDoctype = mXmlDocument.Cr eateDocumentTyp e("this has spaces in between",
null, null, null);
It also crashes my explorer. :-(

But this fixes it
mDoctype = mXmlDocument.Cr eateDocumentTyp e("this_has_spa ces_in_between" ,
null, null, null);

I do like the XML file format!
I only hope that Micrsoft does something to make it more stabel.
Nov 15 '05 #8

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

Similar topics

10
2044
by: Picho | last post by:
Hi all, Lets say I have a "secret" I wish to "hide", lets say a database password. For the more detailed problem, a web application/service that uses a connection string. all the solutions I came up with (embedding in code, encrypting-decrypting) involve embedding the/another secret in the code. since my problem cannot request a user...
11
9217
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in C++. I find my self sometimes, trying Object app = Object(); Object *app = Object(); Object app = new Object();
7
5972
by: MrNobody | last post by:
I was a Java developer so I'm used to using property files as a means to keep configuration settings for my apps. I'm wondering what options are there with ..NET? Some settings I want to include are like a root directory for a target program on the user's machine my app uses, which they would be prompted to supply at startup. Normally the...
1
5318
by: vkrasner | last post by:
It works with VS2003 and does not in VS2005: in VS2003 : string sMyvalue = ConfigurationSettings.AppSettings; in VS2005 (does not work!!) string sMyvalue = ConfigurationManager.AppSettings; Anybody able to give me idea how-to read by C# element which I add to the machine.config into the new single section?
2
1609
by: Marty McDonald | last post by:
Many of our apps are in production and they do not have proper error logging in them - unhandled errors are seen by the users in the form of error messages and stack traces. I know how to make apps handle their errors (global.asax.cs "application_error" event, web.config "customErrors" section, etc). But can I do this without having to visit...
2
5404
by: rrossney | last post by:
Please look at the "what I've already done" section of this message before responding to it: I believe that I've done everything that the people who experience this error are typically told to do. I have created an ASP.NET web service that I have running on my development machine, and am trying to get it to run on my test server. Both...
14
5717
by: Keith | last post by:
I have an MDE application used by several hundred people in different parts of the world. The majority of users are of lesser experience computer experience. The app consists of a frontend (MDE) and backend (MDB), a help file and a key file. To this point, I have provided users with an installation package which installed both files into...
1
2866
by: John | last post by:
Hi I am looking for an editor that will allow a user to edit application configuration easily and I have found below; http://www.codeproject.com/KB/cs/configeditor.aspx Unfortunately it does not read my app.config (given below). Could someone please give me a quick hint as to what can I do to fix this?
21
213
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. As for where to store it, I use os.path.expanduser("~") to find the
0
7664
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7921
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...
1
7437
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...
0
4958
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...
0
3465
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1900
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1023
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
720
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...

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.