Read in a CSV file using C# Razor in Umbraco and Display the details:
@{
try {
var dataFile = Server.MapPath("~/App_Data/Contact-List.csv");
Array csvData = File.ReadAllLines(dataFile);
int dataStartsRow = 5;
int thisRow = 0;
<h2>Reading File Starting at 5th Row, because that is where the data Starts</h2>
foreach (string dataLine in csvData)
{
thisRow = thisRow +1;
int columnInSpreadsheet = 0;
foreach (string dataItem in dataLine.Split(','))
{
if (thisRow >= dataStartsRow)
{
@dataItem <br />
}
}
}
}
catch {
<h2>Error: Check to see if the file Contact-List.csv exists and is not open.</h2>
}
}
Comments
Post a Comment