Reading a txt file to set properties ?
-
I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:
-
I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:
Anonymous wrote: private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; }
private Hashtable ReadFile(string filename)
{
string s;
Regex re = new Regex(@"^\s*(?<name>\w+)\s*=\s*(?<value>.+?)\s*$",
RegexOptions.ExplicitCapture);
Hashtable nv = new Hashtable();
StreamReader sr = File.OpenText(filename);
while ((s = sr.ReadLine()) != null)
{
Match m = re.Match(s);
if (m.Success)
{
nv.Add(m.Groups["name"].Value, m.Groups["value"].Value);
}
}
sr.Close();
return nv;
} -
I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:
Sounds like what I use .ini files for. I think there's a C# article on Code Project that encapsulates WritePrivateProfileString and ReadPrivateProfileString. Or you could DLLImport them and roll your own. Delphi has a pretty nice TIniFile class so what I did was write a dual-interface COM wrapper for it so I could use it with anything that can use COM. I haven't tried it with C# yet though. It worked fine with VB 6 and VC++ 6.
-
I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:
-
I'm looking to read a text file that has properties coded on it ex : name=Joe and can set a control with those properties at run time. Here is an example of what i've coded for this already : private void ReadFile() { StreamReader sr; string ;s sr = File.OpenText("c:\\Test.txt"); s = sr.ReadLine(); sr.Close(); tabPage1.Text = s; } I need to start setting the numberOfTabs I want, the Alignment of the tabs. :wtf:
It is kind of like any INI file, but you instead of initializing the component on startup, you are just setting its propeties. I realize this is not the best way to do this, however this is an exercise I must complete. Thanks for the replies, any other ways of doing this ?