"Steve" <ma******@yahoo.com> wrote in message news:<04****************************@phx.gbl>...
Can anyone tell me the preferred method for writing and
retrieving persistent information using .Net.
Specifically, I am referring to information that you used
to see in registry keys or .ini files like the name of a
database or connection string.
I have read several articles indicating that .config files
are now used, but I am confused because they are read-
only. If I want to write information from within the
application (When a user makes a selection) to a
persistent location so that I can retrieve that
information the next time the application is run, what
method do I use?
Any help is much appreciated.
Steve, you have a couple of options. First, you can still use the
registry (it hasn't gone away). There are .NET classes for working
with the registry that make it a valid .NET option and a simple one to
implement. app.config is another option (as this is the one our team
uses most often). As another poster pointed out you can use the XMLDom
classes to write to the app.config to get at what you want.
The third option may be your best bet. Create a new DataSet object and
populate it (by SQL query or manually adding rows dynamicly with code)
then call the DataSet's .WriteXml method to persist the object to XML.
You can then create a new DataSet object and call it's .ReadXml method
to restore your persisted data. This approach is flexible because the
end result is XML serialized instance of your data. Unlike app.config
and the registry it isn't bound to a certin location or system
resource. If you wanted you could create a web service to
store/retrieve the object without having a file system.
You could build you own system to handle this, but it's nice to
leverge what's built in for you.