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

Popular posts from this blog

Umbraco - Reset the Admin Password via SQL Server

Create a .NET Contact Form that Gets the Last Url Visited in C# Can also be Used in Umbraco

Umbraco Macro for IFrame when Embedding Video, Vimeo Universal Player, or other types of IFrame on to a Page XSLT version and Razor Version