PDA

Click to See Complete Forum and Search --> : Trouble with a Ini Class


Crash893
Apr 23rd, 2007, 07:19 PM
Hi all

I am trying to read 2 values from an Ini file

I am useing the class from this web page ( i can post the source if you dont want to download it)


but when i use the lines

IniReader ini = new IniReader(@"\\filervoca\groups\edit\public\iPass\Billpass config\billpass25.ini");
ini.Write("Section1", "KeyString", "PR AD CI GC MK ED FI IT HR DC UW UN");
ini.Write("Section1", "KeyTest", @"c:/test.txt");
string str = ini.ReadString("Section1", "KeyString");
string tem = ini.ReadString("Section1", "KeyTest");

And the first line (string str) works fine
the second line (string tem) Will not pick up th evalue no mater what i do

It writes the value fine
if i change the varables to match STR exactly ( Section1, KeyString) it still will not pick up a value.

If i change STR variables to the KeyTest it will pick up the correct variable


It seems like it just doesnt like being used twice
so i even went as far to delcare the class again in a diffrent section of code as INI2 and still it wont work.

any ideas

im really stuck

Crash893
Apr 23rd, 2007, 07:24 PM
just as a note lines 2&3 are just for trouble shooting to show that i can write a value

they will be removed in the actuall code

Jumpercables
Apr 23rd, 2007, 11:21 PM
Can really see why one would act different then another maybe post the code for the readString method.

Crash893
Apr 24th, 2007, 09:47 AM
IniFile ini = new IniFile(@"\\filervoca\groups\edit\public\iPass\Billpass config\billpass25.ini");
//ini.Write("Info", "Department", "PR AD CI GC MK ED FI IT HR DC UW UN");
//ini.Write("Section1", "KeyString", "PR AD CI GC MK ED FI IT HR DC UW UN");
ini.IniWriteValue("Section1", "KeyTest", @"c:/test.txt");
string str = ini.IniReadValue("Section1", "KeyString");
string tem = ini.IniReadValue("Section1", "KeyTest");
department = str.Split(' ');



Here is the Class


namespace Ini
{
/// <summary>
/// Create a New INI file to store or load data
/// </summary>
public 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);

/// <summary>
/// INIFile Constructor.
/// </summary>
/// <param name="INIPath"></param>
public IniFile(string INIPath)
{
path = INIPath;
}
/// <summary>
/// Write Data to the INI File
/// </summary>
/// <param name="Section"></param>
/// Section name
/// <param name="Key"></param>
/// Key Name
/// <param name="Value"></param>
/// Value Name
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}

/// <summary>
/// Read Data Value From the Ini File
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Path"></param>
/// <returns></returns>
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp,255,this.path);
return temp.ToString();

}
}
}

Crash893
May 14th, 2007, 02:59 AM
bump