.NET INI, Reg or Resource?

archer_coal

Regular
Joined
Apr 4, 2003
Messages
96
What is the best method for storing user settings?

I have an application that needs to store a few. I don't have much experience with setting them in the registry but i'm willing to learn if that is the best method.

INI files are easy enough but they have their limitations and are all to easily deleted or tamperd with.

Any opinions and or tutorials for registry editing would be great!
Thanks

-mc
 
I tend to use the registry as I think it neater than using ini files.
 
RE:

yea after doing some research I think the registry is the way to go. In the long run it's probably best to learn that now anyway.
btw HOG your quote is too funny man haha. :D

thanks
 
Personally I use XML files. INI hasn't been a recommended means of storing settings since Windows 3.1, and .NET's xcopy deployment mindset lends itself to XML files more than it does to using the registry.
 
INI files aren't even an option anymore. Use XML files, storing them in the user's application data directory and not in the directory of the application. System administrators who have more than three brain cells won't have write/modify permissions set to the Program Files directory.
 
Just out of curiosity, why would you prefer to use and XML over the registry, is there an advantage in doing so?


archer_coal, you'd be suprised at how many times I've had to explain it to people.......duh?? :-)) glad u like it
 
As divil pointed out, an XML file can easily be copied with rest of your application. Using the registry would require an admistrator to go the registry to make any configuration changes. If we're talking about a server-deployed solution, an XML file is WAY easier to manage versus the registry.

Also, .NET was made to read configuration information from a config file. Ever notice the "(DynamicProperties)" property on every control?

And to extend Derek's point, writing to the registry may require priveleges that you don't want your application to have. Whereas reading an XML file from the current directory is pretty much a given for any application.

-Nerseus
 
Why do you think XML is better than INI? Especially in a situation where user might need to modify them?
 
vnarod, as I said, INI files have not been a recommended method of storage since Windows 3.1. Time to let them go.
 
OK, so now you got me thinking.

My app at the moment has a setup form which allows users to specify certain attributes of the application which I write to the registry using SaveSetting and GetSetting. So are you saying I should drop this and adopt the XML approach? I know how to open an XML file and modify it manually by copying the layout already in it, but have no idea how to create one from scratch!
 
Using XML basics is quite easy
Visual Basic:
Public Sub WriteXML(ByVal Path as String)
Dim WriteXML As System.Xml.XmlTextWriter = New System.Xml.XmlTextWriter(Path, System.Text.Encoding.Default) 'Create an XML writer

            With WriteXML
                .WriteStartElement("MyXMLfile") 'Write entry

                .WriteElementString("Hello", "Welcome")

                .WriteEndElement() 'close root

                .Close() 'Stop writing
            End With
End Sub

Public Function GetXML(Byval Path as String) as String
Dim ReadXML As System.Xml.XmlTextReader = New  Xml.XmlTextReader(Path) 'Create a reader
            With ReadXML
                .ReadStartElement("MyXMLfile") 'Read root

                GetXML = .ReadElementString("Hello")

                .ReadEndElement() 'close root section

                .Close() 'Stop reading
            End With
End Function
The XML file looks like this:
Code:
<MyXMLfile><Hello>Welcome</Hello></MyXMLfile>
 
Back
Top