How to read Values from ini File in C#
Read Values from Configuration file i.e ini files
in C#
This is a code to read ini file.
Steps to be followed:
1.First Create a ini file with .ini extention.
2.Copy this piece of text in emp.ini file
3.Save it as C:\\emp.ini
Copy this text as it is.
[iniexample]
ABC=4
Version=1
XYZ=10
Now in Visual Studio Open a Windows Application in C#.
Copy this Code to read Values
public void read()
{
string line;
string deviceName = string.Empty;
// Read the file and display it line by line.
StreamReader file = new
System.IO.StreamReader("c:\\emp.ini");
{
while ((line = file.ReadLine()) != null)
{
if (line.ToLower().StartsWith("xyz"))
{
string[] fullName = line.Split('=');
deviceName = fullName[1];
break;
}
}
}
label1.Text = deviceName;
}
//in Button Click Event
//call the read Method.
//read();
Thats all.
Nice code..
Thanks & Regards
Amol