Thursday, March 22, 2012

working with txt/csv files

ok i basically have a txt file which could be changed to a csv file. but above and beyond that, i am basically trying to open it up in a stream at this point and it keeps giving me the following error.

System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.

here is the code i am currently using, maybe someone will see something wrong and help me out.


StreamReader sReader = File.OpenText("C:\ascdata.txt");
string extractData = null;

while ((extractData = sReader.ReadLine()) != null)
{
ListBox1.Items.Add(extractData);
}

sReader.Close();

my ultimate goal is to be able to run this txt file into an xml file that would then upload into a DB.

I am sure i will be back on the forum with that question unless someone could point me to some good links on that.

oh BTW this is C#ok well i just figured out what my problem was:

OLD CODE


StreamReader sReader = File.OpenText("C:\ascdata.txt");

string extractData = null;

while ((extractData = sReader.ReadLine()) != null)

{

ListBox1.Items.Add(extractData);

}

sReader.Close();

NEW CODE (double \\ on c:\\)


StreamReader sReader = File.OpenText("C:\\ascdata.txt");

string extractData = null;

while ((extractData = sReader.ReadLine()) != null)

{

ListBox1.Items.Add(extractData);

}

sReader.Close();

now my problem is is that it is reading the data twice...i have a test file with like 5 rows, but it is showing them twice.

any way to just show it once?

0 comments:

Post a Comment