| | |
using INI(setting) file in c#
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 26
Reputation:
Solved Threads: 0
hi,
I want to access ini file in my application , which asked for the centre ID b4 login & starts, it asked this only for one tym when it start at first tym & never asked this question again.
The second reason to use ini file is , i want to pass a string of database connection from the ini file to my connection.dll file, bcz the connections details can be change in future, so i cnt hard coded it in my application.
Can any one tell me how to use this from ini file.
actually i m new to these file concepts , so i hv no idea for that. so pls provide me some steps or code 4 that.
Thanx in advance
I want to access ini file in my application , which asked for the centre ID b4 login & starts, it asked this only for one tym when it start at first tym & never asked this question again.
The second reason to use ini file is , i want to pass a string of database connection from the ini file to my connection.dll file, bcz the connections details can be change in future, so i cnt hard coded it in my application.
Can any one tell me how to use this from ini file.
actually i m new to these file concepts , so i hv no idea for that. so pls provide me some steps or code 4 that.
Thanx in advance
0
#3 20 Days Ago
You could also look into settings to store application data.
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
0
#5 20 Days Ago
Can you clarify something please; is an INI file format required or just the way you assumed it would be done? ie, do the INI files already exist and you have to implement them, or will you be creating the files specifically for your application?
If its the later then i would definitely recommend using the built in Settings i linked to above. When you create tableadapters, Visual Studio stores the connection string there by default.
Whilst rolling your own solution can allow a higher level of customisation and control, i really think the built in system does what you need
If its the later then i would definitely recommend using the built in Settings i linked to above. When you create tableadapters, Visual Studio stores the connection string there by default.
Whilst rolling your own solution can allow a higher level of customisation and control, i really think the built in system does what you need
Please don't take for granted the work that solvers do for you. Take the time to fully understand the code they give you so that you might adapt it to future problems.
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
"Learning is more than absorbing facts, it is acquiring understanding.” - William Arthur Ward
0
#7 19 Days Ago
You're shooting yourself in the foot if you want to use ini files. Traditionally those files are stored in the same directory as the application and with windows Vista and later versions of windows you have something called virtualized folders. That means when you write to C:\Program Files\YourApp\YourFile.ini the write will succeed but it really wraps the file to C:\Documents and Settings\...\. When you go to access it you will see the same thing. When another user logs in then the .ini file won't be there.
Don't use .ini files.
Don't use .ini files.
•
•
Join Date: Oct 2009
Posts: 7
Reputation:
Solved Threads: 0
0
#8 19 Days Ago
create IniFile.cs and copy/paste code below. Change namespace.
Use ini class in your code like this:
INIfile could be name of ini file if ini is located in same directory as your c# application(relative path) or absolute path.
C# Syntax (Toggle Plain Text)
using System; using System.Collections.Generic; //using System.Linq; using System.Runtime.InteropServices; using System.Text; namespace YourNameSpace { class IniFile { public string path; [DllImport("kernel32")] private static extern long WritePrivateProfileString(string section, string key, string val, string filePath); [DllImport("kernel32")] private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath); public IniFile(string INIPath) { path = INIPath; } public long IniWriteValue(string Section, string Key, string Value) { long ret = WritePrivateProfileString(Section, Key, Value, this.path); return ret; } public string IniReadValue(string Section, string Key) { StringBuilder temp = new StringBuilder(255); int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.path); return temp.ToString(); } } }
Use ini class in your code like this:
C# Syntax (Toggle Plain Text)
IniFile ini = new IniFile(INIfile); string tmp = ini.IniReadValue("SectionName", "KeyName");
INIfile could be name of ini file if ini is located in same directory as your c# application(relative path) or absolute path.
![]() |
Similar Threads
- Invalid Boot.ini file booting from C:\windows (Windows NT / 2000 / XP)
- php.ini confusion (PHP)
- Overwrite file print setting in CMD (C#)
- Php ini setting--mail function (PHP)
- SYSTEM.INI - device file missing, no file name given (Windows 95 / 98 / Me)
- Setting up File Sharing on Windows XP (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: click events for rutime generated controls
- Next Thread: lines in a text file
| Thread Tools | Search this Thread |
.net access algorithm alignment app array barchart bitmap box broadcast c# c#gridviewcolumn check checkbox client combobox communication control conversion csharp custom database datagrid datagridview dataset datatable datetime degrees development draganddrop drawing elevated encryption enum event excel file focus form format forms function gdi+ hospitalmanagementsystem httpwebrequest image index input install java label list listbox localization login mandelbrot math messagebox mouseclick mysql operator path photoshop picturebox pixelinversion plotting pointer post programming radians read regex remote remoting richtextbox server sleep socket sql statistics stream string stringformatting sun table text textbox thread time timer update usercontrol validation visualstudio webbrowser whileloop windows winforms wpf xml






