![]() |
| | #1 |
| Registered User Join Date: Jun 2006
Posts: 23
| Problem with opening file and pathname I'm new to the boards. I have a problem opening a file for reading. Here are snipets of code I am using. 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) { }
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 |
| stevespai is offline | |
| | #2 |
| pwns nooblars Join Date: Oct 2005 Location: Portland, Or
Posts: 1,094
| "\\" =='\' |
| Wraithan is offline | |
| | #4 |
| Registered User Join Date: Jun 2006
Posts: 2
| Look at the MSDN docs on System.IO.Path, specifically System.IO.Path.Combine(string, string) Don't reinvent the wheel or brute force things when there are already framework methods to do the work for you. -Casey |
| caseymanus is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Problem with readlink()? | QuietBoi | C Programming | 15 | 04-08-2007 05:55 AM |
| Bitmap Displaying Problem | MadCow257 | Game Programming | 0 | 01-25-2005 05:21 PM |
| getting filenames | madsmile | C++ Programming | 4 | 03-12-2002 02:40 PM |
| header file compile error | Unregistered | C Programming | 5 | 02-23-2002 06:28 AM |
| file pointers + recursion = sore head | korbitz | C Programming | 4 | 12-18-2001 05:55 PM |