473,387 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Best Practice for Writing and Retrieving Persistent Info?

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
8 4475
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
"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
"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
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
-----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
> | 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
-----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
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: Paul Rubin | last post by:
I've had this recurring half-baked desire for long enough that I thought I'd post about it, even though I don't have any concrete proposals and the whole idea is fraught with hazards. Basically...
131
by: Peter Foti | last post by:
Simple question... which is better to use for defining font sizes and why? px and em seem to be the leading candidates. I know what the general answer is going to be, but I'm hoping to ultimately...
7
by: Sidd | last post by:
Hi, I tried finding and example of multithreaded client-serve program in python. Can any one please tell me how to write a multithreaded client-server programn in python such that 1.It can handle...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
20
by: Keith G. Murphy | last post by:
I'm trying to get a feel for what most people are doing or consider best practice. Given a mod_perl application talking to a PostgreSQL database on the same host, where different users are...
3
by: Marc Gravell | last post by:
Kind of an open question on best-practice for smart-client design. I'd really appreciate anyones views (preferably with reasoning, but I'll take what I get...). Or if anybody has any useful links...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
6
by: mirandacascade | last post by:
Assume the following: 1) multi-user environment 2) when user opens app, want to run some code that retrieves some information specific to the user...retrieving this information is somewhat i/o...
5
by: Frank Millman | last post by:
Hi all This is not strictly a Python question, but as I am writing in Python, and as I know there are some XML gurus on this list, I hope it is appropriate here. XML-schemas are used to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.