Best Practice for Writing and Retrieving Persistent Info?

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

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.
 
You can use XMLDom to work with the config file..or u can go for making your own xml configuration files which stores the user preference, coz the big boyz says that, it is not advisable to store user preference in app.config file..

Regards.
NetPointer
 
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.

app.config:

<appSettings>
<add key="a" value="someSetting" />
</appSettings>

cs file:

using System.Configuration;

string a = ConfigurationSettings.AppSettings["someSetting"];

if(a==null)
throw new ConfigurationExeception("a needs to be configured");
 
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.

addendum:

when you'll want to save some settings you will have to overwrite the
config file from your code.

or you'll just use your own xml files.

if those settings are per-user better store them in xml files in the
user/ApplicationData directory.
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Are you looking for the C# equivalent of Java Preferences API (or
previously java.util.Properties)? I would look at
System.IO.IsolatedStorage if I were you :)

Steve wrote:

| Can anyone tell me the preferred method for writing and
| retrieving persistent information using .Net.

- --
Ray Hsieh (Djajadinata)
ray underscore usenet at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/m/y8wEwccQ4rWPgRAuJwAJ90EPmIlmZ1PuM3bGO37U3QVML5CACghJ0u
x+zmc03vLZg+F/2MJG7bvrI=
=G+xh
-----END PGP SIGNATURE-----
 
| Can anyone tell me the preferred method for writing and
| retrieving persistent information using .Net.

The most basic conceptual way of doing this is in one page:

string myPersistantInformation = "Are you talking to me?";
Session[ "mySessionValue1" ] = myPersistantInformation;

You can go from page to page in your application session and from any page:

string myPersistantInformationXYZ = Session[ "mySessionValue1"];

myPersistantInformation can be any type of data including a DataSet. Of
course theres somewhat more to State Management. Here are some helpful
links:

Introduction to Web Forms State Management:
http://msdn.microsoft.com/library/d...bconIntroductionToWebFormsStateManagement.asp

State Management Recommendations"
http://msdn.microsoft.com/library/d...vbcon/html/vbconchoosingserverstateoption.asp

A lot of this goes hand in hand with the type of data access method you
pick. If you really want to get into it here's a start:

Recommendations for Data Access Strategies:
http://msdn.microsoft.com/library/d.../vbconusingdatacommandversususingdatasets.asp
 
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Steve was asking about something equivalent to the Windows Registry or
..ini files, which are persistent beyond the lifetime of an application.
Sessions are hardly persistent in this regard--even Application
information are limited by the lifetime of the web application.

Database is persistent, although I doubt that's what he meant. You don't
really put connection strings in a database, eh. That'd be a catch22! ;)

Empire City wrote:
<snipped>

- --
Ray Hsieh (Djajadinata)
ray underscore usenet at yahoo dot com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQE/nOamwEwccQ4rWPgRAlheAJwJjVf4dTKSFekEu8ZcEPnpQsFc8wCfbQV9
lYdGPLB92+vBI5o2vG8c3zM=
=Djmq
-----END PGP SIGNATURE-----
 
Steve said:
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.
 
Back
Top