public void gridviewfill() { ds = ObjOrdersBll.Invoice_Status_Report(ObjOrdersBo); if (ds.Tables[0].Rows.Count > 0) { if (txtInvoiceNo.Text == "") { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { //ds.Tables[0].Rows[i]["DeliveryDate"] = Convert.ToDateTime(ds.Tables[0].Rows[i].ItemArray[1]).ToString("yyyyMMdd"); //ds.Tables[0].Rows[i]["DeliveryTime"] = ds.Tables[0].Rows[i].ItemArray[2].ToString();//.Replace(':',' ').ToString(); ds.Tables[0].Rows[i]["FromDate"] = DateText(ds.Tables[0].Rows[i].ItemArray[4].ToString()); ds.Tables[0].Rows[i]["Todate"] = DateText(ds.Tables[0].Rows[i].ItemArray[5].ToString()); } } dtExport = ds.Tables[0]; gdvInvoices.DataSource = ds.Tables[0]; gdvInvoices.DataBind(); gdvInvoices.Enabled = true; gdvInvoices.Visible = true; //DataTableToTextFile(dtExport, Server.MapPath("TempImages\\Invoice_Report.txt")); BindText(Server.MapPath("TempImages\\Invoice_Report.txt")); Clear(); }
public void BindText(string filePath) { try { string attachFileName = "Invoice" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".txt"; System.IO.FileInfo file = new System.IO.FileInfo(filePath); Response.ClearContent(); Response.AddHeader("content-disposition", "attachment; filename=" + attachFileName); StringBuilder str = new StringBuilder(); for (int i = 0; i < gdvInvoices.Columns.Count; i++) { str.Append(gdvInvoices.Columns[i].HeaderText + ','); } str.Append("\n"); for (int j = 0; j < gdvInvoices.Rows.Count; j++) { for (int k = 0; k < gdvInvoices.Columns.Count; k++) { str.Append(gdvInvoices.Rows[j].Cells[k].Text + ','); } str.Append("\n"); } Response.Write(str.ToString()); Response.End(); System.Threading.Thread.Sleep(3000); Clear(); } catch (Exception ex) { } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)