Hi All,
I'm new to the boards. I have a problem opening a file for reading. Here are snipets of code I am using.
Here is where I am trying to open the file:Code:/// <summary> /// Create a new reader for the given stream. /// </summary> /// <param name="s">The stream to read the CSV from.</param> public CSVReader(Stream s) : this(s, null) { } /// <summary> /// Create a new reader for the given stream and encoding. /// </summary> /// <param name="s">The stream to read the CSV from.</param> /// <param name="enc">The encoding used.</param> public CSVReader(Stream s, Encoding enc) { this.stream = s; if (!s.CanRead) { throw new CSVReaderException("Could not read the given CSV stream!"); } reader = (enc != null) ? new StreamReader(s, enc) : new StreamReader(s); } /// <summary> /// Creates a new reader for the given text file path. /// </summary> /// <param name="filename">The name of the file to be read.</param> public CSVReader(string filename) : this(filename, null) { } /// <summary> /// Creates a new reader for the given text file path and encoding. /// </summary> /// <param name="filename">The name of the file to be read.</param> /// <param name="enc">The encoding used.</param> public CSVReader(string filename, Encoding enc) : this(new FileStream(filename, FileMode.Open), enc) { }
Now, I want to be able to change the pathname so that my program can process multiple files (using a for loop).Code:using ( CSVReader csv = new CSVReader(@"C:\Documents and Settings\testfile1.csv") )
ie:
"C:\Documents and Settings\testfile1.csv"
"C:\Documents and Settings\testfile2.csv"
"C:\Documents and Settings\testfile3.csv"
...
I tried loading the path into a string variable and using String.Concat( , ) to create the full path. However, I get errors from the '\' within the strings.
Does anyone know anyother way to accomplish what I am trying to do?
Thanks,
Steve



LinkBack URL
About LinkBacks


