Search code examples
c#csvpathstreamreaderabsolute-path

C# Path CsvReader - how to use absolute path


I'm using System.IO.StreamReader passing a string path (@"‪C:\Users\someuser\somefolder\my.csv")

        using (var reader = new StreamReader(filepath))
        {
            var csvReader = new CsvReader(reader);
            var entries = csvReader.GetRecords<SpreadsheetEntry>();
            return entries.ToList();
        }

this throws the following exception:

System.IO.IOException

HResult=0x8007007B Message=The filename, directory name, or volume label syntax is incorrect :

'C:\Users\someuser\Source\Repos\StakeParser\StakeParser\bin\Debug\netcoreapp2.1\‪C:\Users\someuser\Desktop\testspreadsheet.csv' Source=System.Private.CoreLib StackTrace: at System.IO.FileStream.ValidateFileHandle(SafeFileHandle fileHandle) .....

My question is, how do i use this correclty so that I can later pass the fullpath as an argument in the console? , at the moment its starting from the working path instead of taking the absoluth path...


Solution

  • Answer is provided here. Streamreader adds the absolute path to the working path its running at.

    http://www.introprogramming.info/tag/streamreader-class/