By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

Best Practice for Writing and Retrieving Persistent Info?

P: n/a
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.
Nov 15 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
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
Nov 15 '05 #2

P: n/a
"Steve" <ma******@yahoo.com> wrote in news:04ad01c399b0$5096f4b0
$a*******@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.


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");

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #3

P: n/a
"Steve" <ma******@yahoo.com> wrote in news:04ad01c399b0$5096f4b0
$a*******@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.


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.

--
best regards

Peter Koen
-----------------------------------
MCAD, CAI/R, CAI/S, CASE/RS, CAT/RS
http://www.kema.at
Nov 15 '05 #4

P: n/a
On MSDN Microsoft has an Application Block called Application Configuration
Application Block, or something to that effect. http://msdn.microsoft.com/ .
That might help you out.
-mike
MVP

"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.

Nov 15 '05 #5

P: n/a
-----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/y8wEwccQ4rWPgRAuJwAJ90EPmIlmZ1PuM3bGO37U3QVML5CACg hJ0u
x+zmc03vLZg+F/2MJG7bvrI=
=G+xh
-----END PGP SIGNATURE-----

Nov 15 '05 #6

P: n/a
> | 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/de...Management.asp

State Management Recommendations"
http://msdn.microsoft.com/library/de...tateoption.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/de...ngdatasets.asp
Nov 15 '05 #7

P: n/a
-----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/nOamwEwccQ4rWPgRAlheAJwJjVf4dTKSFekEu8ZcEPnpQsFc8w CfbQV9
lYdGPLB92+vBI5o2vG8c3zM=
=Djmq
-----END PGP SIGNATURE-----

Nov 15 '05 #8

P: n/a
"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.
Nov 15 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.