How to write config.ini ??

A

Agnes

Can I write a file like config.ini which store the server-name, userid &
password,
So, my application can read the config.ini file and get the server - name,

Does my concept is correct ?
If yes, do any web site can provide the sample of such file or provide
tutorial ??
For my current stage, i got a class object and assign the server-name to a
property, even form will call this class object.
Please give some advice.
p.s - It is my 1st time to do vb.net deployment
 
K

Ken Tucker [MVP]

Hi,

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet02122002.asp

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnadvnet/html/vbnet07082003.asp

Ken
----------------
Can I write a file like config.ini which store the server-name, userid &
password,
So, my application can read the config.ini file and get the server - name,

Does my concept is correct ?
If yes, do any web site can provide the sample of such file or provide
tutorial ??
For my current stage, i got a class object and assign the server-name to a
property, even form will call this class object.
Please give some advice.
p.s - It is my 1st time to do vb.net deployment
 
G

Guest

Hi Agnes

You are thinking along the right lines - the .ini file is now a .config
file: for an app like Test.exe, the file would be called Test.exe.config.

However: you must consider the security impact of data like userid /
password being stored in the file...

As a quick intro, in Visual Studio .NET, you create a file called app.config
in your solution (add a new Application Configuration file to the solution,
and this will be done for you). Then the build process will automatically
change the filename to the correct one for you.

The config file uses XML - the easiest way to get started using dynamic
properties is in the design time view, select a control (say your Form), and
scroll to the top of the properties window - select Dynamic Properties, and
click on the ... button. Select Text, and you will see that your app.config
file will have been modified like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!-- User application and configured property settings go here.-->
<!-- Example: <add key="settingName" value="settingValue"/> -->
<add key="Form1.Text" value="Form1" />
</appSettings>
</configuration>

You will also notice that the text property in the properties window will
have a small blue glyph by it indicating that it is a dynamic property, and
the following code will have been added into the design time environment for
you too.

Dim configurationAppSettings As System.Configuration.AppSettingsReader = New
System.Configuration.AppSettingsReader
Me.Text = CType(configurationAppSettings.GetValue("Form1.Text",
GetType(System.String)), String)

When you build the application, you will find that you can change the
..config file, and when you start your application, it will read the
information from the config file.

HTH

Nigel Armstrong
 
A

Agnes

Thanks Nigel, I will try to build a small application to test the config.
Thanks Ken, I will go through the msdn web site
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top