jasonsalas
IS-IT--Management
Hi everyone,
I've been wondering why this isn't working: I was curious and wanted to rebuild the old MWSC.NextLink control that shiiped with ASP 3.0 for ASP.NET.
Essentially, I'm trying to read from a tab-delimited text file (2 columns) and have the values before and after the tab be added to a Hashtable. But for some reason, I eep drawing an ArgumentOutOfRangeException when trying to run the code. Specifically, I get "Length cannot be less than zero. Parameter name: length", indicating that no data's being read-in.
private Hashtable GetFileList(string file)
{
Hashtable ht = new Hashtable();
StreamReader sr = File.OpenText(file);
// TODO: somewhere in here the code is going wrong...it works otherwise....
while(sr.Peek() > -1)
{
string contents = sr.ReadLine();
tabPosition = contents.IndexOf("\n",0);
before = contents.Substring(0,tabPosition); // the Hashtable's key
after = contents.Substring(tabPosition+1); // the Hashtable's value
ht.Add(before,after);
}
sr.Close();
return ht;
}
Any ideas?
Thanks!
Jas
I've been wondering why this isn't working: I was curious and wanted to rebuild the old MWSC.NextLink control that shiiped with ASP 3.0 for ASP.NET.
Essentially, I'm trying to read from a tab-delimited text file (2 columns) and have the values before and after the tab be added to a Hashtable. But for some reason, I eep drawing an ArgumentOutOfRangeException when trying to run the code. Specifically, I get "Length cannot be less than zero. Parameter name: length", indicating that no data's being read-in.
private Hashtable GetFileList(string file)
{
Hashtable ht = new Hashtable();
StreamReader sr = File.OpenText(file);
// TODO: somewhere in here the code is going wrong...it works otherwise....
while(sr.Peek() > -1)
{
string contents = sr.ReadLine();
tabPosition = contents.IndexOf("\n",0);
before = contents.Substring(0,tabPosition); // the Hashtable's key
after = contents.Substring(tabPosition+1); // the Hashtable's value
ht.Add(before,after);
}
sr.Close();
return ht;
}
Any ideas?
Thanks!
Jas