Hardik Patel

Hardik Patel

  • NA
  • 378
  • 469.5k

store excel in folder on button event without save option?

Oct 23 2013 4:54 AM
how to generate excel from dataset and store it in folder without save option?

i am using below but it asked for the  save option.


  ds = new DataSet();
        ds = sq.ExecuteDataSet("Filllresult1", param);
        if ((ds != null) && (ds.Tables.Count != 0) && (ds.Tables[0].Rows.Count != 0))
        {
           
            HttpResponse response = HttpContext.Current.Response;
            response.Clear();
            //response.Charset = "";
            response.ContentType = "application/vnd.ms-excel";
            response.AddHeader("Content-Disposition", "attachment;filename=Smarks.xls");
            //string filename = "Mark" + p; 
            //response.AddHeader("Content-Disposition", "C:\"" + fileName + "\"");
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            DataGrid dg = new DataGrid();
            dg.DataSource = ds;
            dg.DataBind();
            dg.RenderControl(htw);
            response.Write(sw.ToString());
            response.End();
        }


Answers (1)