473,320 Members | 2,035 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,320 software developers and data experts.

.NET version of INI files ?

Im rewriting a current MFC application for .NET using C++\CLI that
compiles \clr SAFE.

My application needs to read application settings, it used to do this
from the old application ini file via GetProfileString etc.

What is a direct .NET equivalent of this?

Generally it only needs to read custom properties etc that have been
pre-set.

I guess its somewhere off System::Configuration ???

I found this article
http://www.codeproject.com/csharp/ReadWriteXmlIni.asp

Im just surprised someone should have to write classes to achieve this.

Dec 14 '05 #1
3 2281
Herby wrote:
Im rewriting a current MFC application for .NET using C++\CLI that
compiles \clr SAFE.

My application needs to read application settings, it used to do this
from the old application ini file via GetProfileString etc.
Well, you could call this API via platform invoke (or IJW), but INI
files are not the .NET way to do things.
What is a direct .NET equivalent of this?
The config file. These are application domain based and they are
associated with an application, (ie not a DLL). When an application
domain is started (there will be at least one for each process instance)
the runtime will create an in-memory cache. When you (or runtime
classes) read a configuration section it will be read from file and then
cached in memory, so subsequent reads of the section will use the cached
value. The section will be read from global configuration file
machine.config and the application config file. The two are merged and
values in the latter take precedence over the former. The application
configuration file has the name of the process with the .config suffix
(eg myapp.exe.config). Configuration files are XML files. You can create
your own sections but the schema allows you to use <appSettings> for
simple settings:

http://msdn.microsoft.com/library/en...ngsElement.asp

This element is a collection of <add> elements where each one has key
and value attributes. You can use the AppSettingsReader class to read
these values:

http://msdn.microsoft.com/library/en...ClassTopic.asp

Gall GetValue with the key name and the type of the value attribute to
get the value.
Generally it only needs to read custom properties etc that have been
pre-set.
The configuartion file is ideal for this because it will read the values
*once* from the configuration file.
I guess its somewhere off System::Configuration ???

I found this article
http://www.codeproject.com/csharp/ReadWriteXmlIni.asp

Im just surprised someone should have to write classes to achieve
this.


Well, Microsoft insists on putting XML *everywhere* and so INI files had
to be junked because they did not contain XML. By the way, config files
are not real XML files, because they do not implement the complete DOM.
The reason is that they are not read by the System.Xml classes they are
read by lightweight classes that only read a subset of XML.

Richard
--
Fusion Tutorial: http://www.grimes.demon.co.uk/workshops/fusionWS.htm
Security Tutorial:
http://www.grimes.demon.co.uk/workshops/securityWS.htm
Dec 14 '05 #2
Thanks Richard, very informative, lots of reading and catching up to do
there.
I could not use "IJW" because my application is to run in a highly
secure setting and so must compile as /safe.
I assume reading custom application settings from a .config file is not
in anyway a security issue?

Dec 14 '05 #3
On Wed, 14 Dec 2005 15:18:30 -0000, "Richard Grimes"
<ri******@mvps.org> wrote:
Herby wrote:
What is a direct .NET equivalent of this?
The config file.
... The application
configuration file has the name of the process with the .config suffix
(eg myapp.exe.config). Configuration files are XML files.


If memory serves, Richard, you wrote a sample program that illustrates
use of .config files. I remember using the built-in functions for
access to them, but couldn't figure out why settings were getting
overwritten. Turned out that Visual Studio was copying over the
modified file. This occurred with your sample code as well.

When run outside the debugger all was well.
Well, Microsoft insists on putting XML *everywhere* and so INI files had
to be junked because they did not contain XML.


Haha! That does seem to be the case sometimes.

I'm at least hoping that registry abuse tapers down. That's probably
the biggest single reason people have to reinstall XP every couple
years. I've seen a spyware checker (Spywareblaster maybe?) that
copied the entire 'favorites' folder into the registry. On some
machines that's 10,000 new registry keys. Most often, registry pigs
don't clean up after themselves either.

Dec 22 '05 #4

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

Similar topics

4
by: Julie Siebel | last post by:
Apologies...I'm sure this has been asked before, but I can't seem to come up with the correct Google search terms. While my problem is with stylesheets, the errors are being caused by my...
0
by: Neil Sargent | last post by:
This is a general posting of how I fixed a problem created by using the Access 97 ODE Setup Wizard on a Windows XP machine. I hope it helps anyone who comes across the problem saves them the 3 days...
7
by: Morley | last post by:
1. Is the run time version a self-contained file which includes Access files and a database or are there separate Access files and a database (.mdb) file? 2. If the database file is separate,...
6
by: D. Yates | last post by:
Hi, I got bit by the fact that applications using library files that are NOT strongly named will use older versions of the library without generating an error, so........ Is there a way to...
0
by: Felix | last post by:
Ok, I've had this issues since yesterday and I cannot figure out what's causing it. Basically, I have a Visual Studio 2005 Web Service. The service runs completely find on my local development...
8
by: Brian Tkatch | last post by:
Server: DB2/SUN 8.1.6 Client: DB2 Connect Personal Edition (No 11) <URL:ftp://ftp.software.ibm.com/ps/products/db2/fixes2/english-us/db2winIA32v8/fixpak/FP11_WR21365/FP11_WR21365_CONPE.exe> ...
7
by: Sky | last post by:
I have been looking for a more powerful version of GetType(string) that will find the Type no matter what, and will work even if only supplied "{TypeName}", not the full "{TypeName},{AssemblyName}"...
0
by: Grant_Sutty | last post by:
Hi The only file information I need to access for a bunch of files (dlls & exe) on several remote servers is "file version number". Using the code below, I appear to be able to access all...
0
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hi all, I have a publishing Click Once of my application. Now I want create new version of my application for modify some files, like app.config.
12
by: lawpoop | last post by:
I'm developing a php website that I have under subversion version control. I'm working on an image upload functionality, and in the middle of it I realized that any files that a user uploads will...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.