I am reading an excel file using my controller. I am storing all the lines of CSV file in an array. When I print it out, I can see the contents of array. But when I iterate through each of the lines and split by comma, I get nothing and as a result I can't store read values.
Here is a sample of my output along with code:
VAWC Neptune flat file is my file. 206 are number of lines in file. Then I am printing line along with its length. And when this line is splitted by commas, I see only first output else everything is empty.
However as we keep on reading other lines, this splitted array doesn't appear.
Here is the section of code which I am using:
//files is only having a single file named VAWC Neptune flat file - new meters for inventory.csv
public ActionResult ReadFile(IEnumerable<HttpPostedFileBase> files)
{
var fileName = Path.GetFileName(files.First().FileName);
var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
files.First().SaveAs(destinationPath);
try
{
string[] read = System.IO.File.ReadAllLines(destinationPath);
System.Diagnostics.Debug.WriteLine(read.Length);
for (int i = 0; i < read.Length; i++)
{
System.Diagnostics.Debug.WriteLine(read[i]);
List<string> s = read[i].Replace(Environment.NewLine,"").Split(new char[] { ',' }, StringSplitOptions.None).ToList<string>();
System.Diagnostics.Debug.WriteLine("Length of words in line:" + s.Capacity);
for (int j = 0; j < s.Capacity; j++)
{
System.Diagnostics.Debug.WriteLine("Data:s[" + j + "]" + s[j]);
}
}
}
I have tried so many possible ways but nothing has worked.