wpf - Odd INI format writing in C#. Can't make it read or write -
i've learned lot on past few months on site. i'm getting little hole here 1 though. i'm trying write or change values in specific ini file.
i'm using custom class made stackoverflow guru name of "danny beckett" , understand. been using while no issue. works while writing , reading ini files... until now.
this talks it. reading/writing ini file
this class i'm using read , write ini's.
using system.io; using system.reflection; using system.runtime.interopservices; using system.text; // change match program's normal namespace namespace myprog { class inifile // revision 10 { string path; string exe = assembly.getexecutingassembly().getname().name; [dllimport("kernel32")] static extern long writeprivateprofilestring(string section, string key, string value, string filepath); [dllimport("kernel32")] static extern int getprivateprofilestring(string section, string key, string default, stringbuilder retval, int size, string filepath); public inifile(string inipath = null) { path = new fileinfo(inipath ?? exe + ".ini").fullname.tostring(); } public string read(string key, string section = null) { var retval = new stringbuilder(255); getprivateprofilestring(section ?? exe, key, "", retval, 255, path); return retval.tostring(); } public void write(string key, string value, string section = null) { writeprivateprofilestring(section ?? exe, key, value, path); } public void deletekey(string key, string section = null) { write(key, null, section ?? exe); } public void deletesection(string section = null) { write(null, null, section ?? exe); } public bool keyexists(string key, string section = null) { return read(key, section).length > 0; } } } this code i'm using make changes....
var myini = new inifile("settings"); var selectedpdata = myini.read("selectedpdata"); var selectedsql = myini.read("selectedsql"); var setupinilocation = selectedpdata + "\\setup\\sidexis\\setup.ini"; var setupini = new inifile(setupinilocation) setupini.deletekey("vzpdata", "client"); setupini.write("vzpdata", selectedpdata, "client"); setupini.deletekey("combosql", "client"); setupini.write("combosql", selectedsql, "client"); what does: reads 2 parameters settings ini file , passes them variables. uses variables write them setup.ini file.
the target "setup.ini"
[client] aufruf="msiexec.exe /i sidexis.msi vzsidexis="c:\sidexis\" sqldialogtype=1 language=1033 propdsn="pdata_sqlexpress" propdbo="" installationtype=full serialnumber=6000000837 vzpdata="\\jonmer-win7x64\pdata\" combosql="jonmer-win7x64\pdata_sqlexpress" companyname="" neededdiskspace=104857600 masterclient=true /qb!" the paramaters need modify are: combosql , vzpdata.
it able modify it... puts them @ bottom. i'm sure has formatting because if format regular ini file. (each parameter on own line) works fine....
Comments
Post a Comment