473,657 Members | 2,496 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 6573
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
2067
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 intervention, I am at a stop.
11
9243
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
5982
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 registry is used for this but I'd rather not use the registry if possible. Isn't there some kind of...
1
5346
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
1611
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 each app? Can this be done at the machine level? I'm looking for a kind of machine-level...
2
5412
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 machines are running Windows 2000 SP4, IIS 5, and the .NET 2.0 framework. When I attempt to access...
14
5728
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 their program files folder with no problems. A few users are getting new computers with vista...
1
2872
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
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8742
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1734
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.