for some reason it seems File.ReadAllLines has an uncanny issue converting all dates from yyyy/mm/dd to yy/mm/dd.
Problem is i am working with historic data that can pull back all the way past 1901, thus causing an issue with shorthand date notation.
public static string[] readFileToStringArray(string filePath = null, string fileName = null)
{
string[] lines = null;
if (File.Exists(filePath + fileName))
{
//lines = File.ReadAllLines(filePath + fileName);
lines = File.ReadAllLines(filePath + fileName, Encoding.UTF8);
string unescape = String.Empty;
List<string> thisCSV = new List<string>();
foreach (string line in lines)
{
unescape = line.Replace("\"", "");
thisCSV.Add(unescape );
}
lines = thisCSV.ToArray();
}
return lines;
}
Weird thing is it does not do this to all files, I have several running this script. I then checked the physical file and everything is in order there.
It is a valid CSV,everything is encapsulated as text.
Any idea how to negate this, as remedying the whole dataset in memory/stream is out of the question? already checked MSDN but no help there.
The only other code involved at this point is a helper method, but irrelevant as the only thing it does is create a list of filenames.
public static List<string> GetFilesinDirectory(string filesPath)
{
List<string> files = new List<string>();
string physicalFilesPath = (string)HttpContext.Current.Server.MapPath(filesPath);
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(physicalFilesPath);
foreach (var file in dir.GetFiles())
{
string thisfile = physicalFilesPath + "\\" + (string)file.Name;
files.Add(thisfile);
}
return files;
}
Thanks