public ActionResult GExport(string f) { try { int intColCount = 0; var mydt = new DataTable("myTableName"); DataColumn mydc; DataRow mydr; int col = 0; var csvReader = new CsvReader(f, Encoding.Default); List<string[]> liststrs = csvReader.ReadAllRow(); string ids = ""; for (int i = 0; i < liststrs.Count; i++) { string[] aryline = liststrs[i]; if (i == 0) { for (int j = 0; j < aryline.Length; j++) { if (aryline[j] == "Cart no.") { col = j; } mydc = new DataColumn(aryline[j]); mydt.Columns.Add(mydc); } } else { mydr = mydt.NewRow(); for (int j = 0; j < mydt.Columns.Count; j++) { if (j == col) { ids += aryline[j] + ","; } if (aryline.Length > j) mydr[j] = aryline[j]; } mydt.Rows.Add(mydr); } } ids = ids.Trim(','); ids = ids.Replace(",", "','"); List<OrderType> list = NSession.CreateQuery("from OrderType where OrderExNo in('" + ids + "')").List<OrderType>().ToList(); foreach (DataRow dataRow in mydt.Rows) { OrderType order = list.Find(p => p.OrderExNo.Trim().ToUpper() == dataRow["Cart no."].ToString().Trim().ToUpper()); if (order != null) { dataRow["Tracking no."] = order.TrackCode; if (string.IsNullOrEmpty(order.TrackCode)) { dataRow["Tracking no."] = order.TrackCode2; } dataRow["Delivery company"] = "Chinapost registered airmail"; } } var ds = new DataSet(); ds.Tables.Add(mydt); Session["ExportDown"] = ExcelHelper.GetExcelXml(ds); return Json(new { IsSuccess = true }); } catch (Exception ex) { return Json(new { IsSuccess = false, ErrorMsg = ex.Message }); } }