Skip to content

Instantly share code, notes, and snippets.

// get the uploaded file from the request
var uploadedFile = base.Request.Files[0];
// create directory if it doesn't exist
if (!Directory.Exists(Server.MapPath("~/Catalogues/Products")))
Directory.CreateDirectory(Server.MapPath("~/Catalogues/Products"));
// get the path where the uploaded csv will be saved
var path = Server.MapPath(String.Format("~/Catalogues/Products/{1}",
"products.csv"));
//create the "database" connection string
string connString = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=\"" + dir + "\\\";"
+ "Extended Properties=\"text;HDR=Yes;FMT=Delimited\"";
//create the database query
string query = "SELECT * FROM " + file;
//create a DataTable to hold the query results
DataTable dTable = new DataTable();
var productDtos = new List<ProductDto>();
try {
foreach (DataRow dr in dTable.Rows)
{
productDtos.Add(new ProductDto()
{
description = dr["Description"].ToString(),
name = dr["Name"].ToString(),
pageNumber = int.Parse(dr["PageNumber"].ToString()),
"name","description","price","thumbUrl","pageNumber"
"Product A","This is product A","1.00","http://someurl.com/producta.jpg","1"
"Product B","This is product B","1.00","http://someurl.com/productb.jpg","2"
"Product C","This is product C","4.00","http://someurl.com/productc.jpg","3"
"Product D","This is product D","2.00","http://someurl.com/productd.jpg","4"
public class MvcApplication : TurbineApplication
{
public MvcApplication()
{
ServiceLocatorManager.SetLocatorProvider(() => new StructureMapServiceLocator());
}
}
namespace VoucherPrototype.Routing
{
public class DefaultRouting : IRouteRegistrator
{
public void Register(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
namespace VoucherPrototype.Registration
{
public class DefaultRegistration : IServiceRegistration
{
public void Register(IServiceLocator locator)
{
locator.Register<IVoucherRepository, VoucherRepository>();
}
}
}
public class VouchersController : Controller
{
private IVoucherRepository _voucherRepository;
public VouchersController(IVoucherRepository voucherRepository)
{
_voucherRepository = voucherRepository;
}
}
<ul>
@foreach (var deal in Model)
{
<li>@deal.Description</li>
}
</ul>
ul {
list-style-type: none;
padding: 0;
}