I have this csv file i need to be able to read and I cant get it to work. here is the csv and a picture of csv. Im not sure what the problem is, I have been following the tutorials so I have a guess that it might be something with the csv file and the spacing it is using. I cannot change anything in the csv. I have tried adding Name properties to the class and also index properties.
CsvHelper version: 27.1.0
public static void Main(string[] args)
{
using (var streamReader = new StreamReader(@"C:\Users\Adam\Desktop\C#\price_detail.csv"))
{
using (var csvReader = new CsvReader(streamReader, CultureInfo.InvariantCulture))
{
var records = csvReader.GetRecords<SKU>();
}
}
}
public class SKU
{
//[Name("PriceValueId")]
public string PriceValueId { get; set; }
//[Name("Created")]
public DateTime Created { get; set; }
//[Name("Modified")]
public DateTime Modified { get; set; }
//[Name("CatalogEntryCode")]
public string CatalogEntryCode { get; set; }
//[Name("MarketId")]
public string MarketId { get; set; }
//[Name("CurrencyCode")]
public string CurrencyCode { get; set; }
//[Name("ValidFrom")]
public DateTime ValidFrom { get; set; }
//[Name("ValidUntil")]
public DateTime ValidUntil { get; set; }
//[Name("UnitPrice")]
public decimal UnitPrice { get; set; }
}
Debug output:
Header with name 'PriceValueId'[0] was not found.
Header with name 'Created'[0] was not found.
Header with name 'Modified'[0] was not found.
Header with name 'CatalogEntryCode'[0] was not found.
Header with name 'MarketId'[0] was not found.
Header with name 'CurrencyCode'[0] was not found.
Header with name 'ValidFrom'[0] was not found.
Header with name 'ValidUntil'[0] was not found.
Header with name 'UnitPrice'[0] was not found.
If you are expecting some headers to be missing and want to ignore this validation, set the configuration HeaderValidated to null. You can also change the functionality to do something else, like logging the issue.
IReader state:
ColumnCount: 0
CurrentIndex: -1
HeaderRecord:
["PriceValueId Created Modified CatalogEntryCode MarketId CurrencyCode ValidFrom ValidUntil UnitPrice"]
IParser state:
ByteCount: 0
CharCount: 101
Row: 1
RawRow: 1
Count: 1
RawRecord:
PriceValueId Created Modified CatalogEntryCode MarketId CurrencyCode ValidFrom ValidUntil UnitPrice