473,581 Members | 2,513 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to save user options and settings to a file, like we used to do with INI files?

I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to a
pristine state and the accumulated user options and application settings are
discarded. What is the accepted way to persist application values to a file
in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com
Nov 25 '06 #1
4 2633
Hello Richard Lewis Haggard" HaggardAtWorldD otStdDotCom,

RThe app config file appears to be updated with values while the
Rapplication is running but when the application closes, the file
Rseems to get restored to a pristine state and the accumulated user
Roptions and application settings are discarded.

Emm, could u explain what do u mean? Why config is restored?

RWhat is the accepted
Rway to persist application values to a file in a WinForms 2
Rapplication?

One of the approaches, besides xml config, is to use Isolation Storage

---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Nov 25 '06 #2
Hi Richard,

"Applicatio n Settings Overview"
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

VS 2005 has built-in support for a single, Default Settings file and
Resources file, per project.

--
Dave Sexton

"Richard Lewis Haggard" <HaggardAtWorld DotStdDotComwro te in message
news:OL******** ******@TK2MSFTN GP03.phx.gbl...
>I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to
a pristine state and the accumulated user options and application settings
are discarded. What is the accepted way to persist application values to a
file in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

Nov 26 '06 #3
Settings file? I saw that but was under the impression that it did not lend
itself well to addition and deletion of values programmaticall y. Did I
misunderstand? Because I thought that it would be difficult to write user
specific application options and MRU list, I deemed that approach
unreasonable. Have I unnecessarily exercised myself in jumping to this
conclusion?

Given that writing an indeterminate number of user specific values to some
sort of persistent storage is such a common requirement, one would have
thought that a consensus as to best practice would have been developed for
which I, only recently having been prized kicking and screaming from the MFC
dark ages, was unaware. I do thank you all for your patience while I flail
randomly about as I try to come up to speed.
--
Richard Lewis Haggard
www.Haggard-And-Associates.com

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:un******** ******@TK2MSFTN GP06.phx.gbl...
Hi Richard,

"Applicatio n Settings Overview"
http://msdn2.microsoft.com/en-us/library/k4s6c3a0.aspx

VS 2005 has built-in support for a single, Default Settings file and
Resources file, per project.

--
Dave Sexton

"Richard Lewis Haggard" <HaggardAtWorld DotStdDotComwro te in message
news:OL******** ******@TK2MSFTN GP03.phx.gbl...
>>I have an application that can't use the registry to save various user
options and application settings. My first thought was to simply use an
application configuration file but this approach seems flawed. The app
config file appears to be updated with values while the application is
running but when the application closes, the file seems to get restored to
a pristine state and the accumulated user options and application settings
are discarded. What is the accepted way to persist application values to a
file in a WinForms 2 application?
--
Richard Lewis Haggard
www.Haggard-And-Associates.com


Nov 27 '06 #4
Hi Richard,
Settings file? I saw that but was under the impression that it did not
lend itself well to addition and deletion of values programmaticall y. Did
I misunderstand? Because I thought that it would be difficult to write
user specific application options and MRU list, I deemed that approach
unreasonable. Have I unnecessarily exercised myself in jumping to this
conclusion?
Yes :)

Take a look at the article I posted and you'll see that even controls can
use the Application Settings architecture. For example, ToolStrip uses
Application Settings to save position information of itself and its items
between application sessions.

The ApplicationSett ingsBase class provides a Save method that you can call
from your application to persist data (the Save method is actually an
overridden form of the SettingsBase.Sa ve method, from which it derives).
You can even create your own SettingsProvide r for persistence outside of the
default local file storage.

Particular settings may be configured to have application-scope or
user-scope in WinForms applications and there is built-in support for
collections as well. IMO, this technology is perfect for persisting a raw
MRU list, per user, as long as the information being persisted isn't
sensitive data that must be secured (although simple, managed cryptography
would probably do the trick).
Given that writing an indeterminate number of user specific values to some
sort of persistent storage is such a common requirement, one would have
thought that a consensus as to best practice would have been developed for
which I, only recently having been prized kicking and screaming from the
MFC dark ages, was unaware. I do thank you all for your patience while I
flail randomly about as I try to come up to speed.
There are no explicitly stated "best practices" that I'm aware of since you
have to consider security, the quantity of the data and the type of the data
(e.g., relational, structured, raw text, raw binary) and because there are
many different places and ways to persist the data (e.g., Application
Settings, application configuration file, Isolated Storage, delimited
flat-file, RDBMS, structured storage, xml file, raw binary file containing a
serialized object-graph, etc.). Application Settings, in the 2.0 framework,
is usually sufficient, but I've seen applications use Isolated Storage, the
application configuration file, an xml file or an RDBMS such as Sql Server
2005 as well.

--
Dave Sexton
Nov 27 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
19469
by: Mark S | last post by:
I have a db maintenance plan which is set to backup (then truncate hopefully) the transaction log. In order to backup a transaction log the db must be in single user mode so the maint. plan fails. How do you automatically set the db, in single user mode, for the transaction log to be backed up then truncated? Also, I manually set the db in...
7
16492
by: Dennis C. Drumm | last post by:
Can my program access the HKEY_LOCAL_MACHINE/Software section of the registry when being used by a user with restricted rights (not with admin rights)? If so, how? I have a program that functions just fine when run by an administrator but generates an exception when run by a restricted user. The program accesses the...
7
15647
by: Arun Kannan | last post by:
Hi We are planning to upgrade a MFC Application (.Exe) to compile on Dot Net Framework. I have opened the application in Visual Studio 2003. I changed the compiler option to /clr. I have set following properties -Basic Run Time checks to Default -Smaller Type Check to N -Runtime Library -Mutlit Threaded Debug threade -Use of MFC - use...
4
5533
by: Richard | last post by:
Hi I'm new to ASP/Web programming so any help would be appreciated... Situation: On my web page I would like to present a link {or button} that would allow the user to download a large file. When the user clicks to start the download I would like to display the "Save As" dialog, allow the user to name a place to save the file, and then...
3
1900
by: Robin Tucker | last post by:
I'm a bit confused about where to put my program settings. Firstly, I can choose (I suppose) between .ini, .xml or the registry. Which one is best? Secondly, *where* do I place any files I generate on a per-user or per-application basis? For example, I cannot place user settings in the \Program Files\My Application directory, because...
0
3589
by: ssg31415926 | last post by:
I've been trying to save a hashtable in an Application Settings file. I need to save settings for each tabPage on a form. Trouble is, the number of tabPages is determined at runtime, so I can't have individual settings for each page. I decided to hold them in a collection. I started out with a generic Dictionary but that didn't work. So,...
5
1945
by: hp_1981 | last post by:
Hi Is there anyway avoiding users to save my web pages? this idea came to my mind when I tried to save a web page, but in the middle of saving progress something like the following error occurred: "unable to save the page...". on the other hand, once, I saved a web page successfully, but when I opened it the characters were completely...
4
3422
by: lfhenry | last post by:
I am a newbie to HADR and Admin of DB2 (I am websphere guy). My question relates to DB2 logging. I've read that HADR does not allow Infinite logging (-1). I am expecting my Database to grow 8-10GB's a month without compression (about 260 Megs day). What logging options should i specify before i start my database. If i set archiving using...
3
4343
by: evenlater | last post by:
I have an Access application on a terminal server. Sometimes my users need to export reports to pdf, rtf or xls files and save them to their own client device hard drives. They can do that right now the way I have this set up, but it's confusing and slow. When they browse for a place to save the reports, they see all of the drives on the...
0
8153
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8309
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8178
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5365
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3830
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1405
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1141
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.