Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

  • *Gurus*
Posted
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.
Posted

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

My website
  • *Experts*
Posted

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

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

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!

My website
Posted

Using XML basics is quite easy

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:

<MyXMLfile><Hello>Welcome</Hello></MyXMLfile>

.Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...