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();
}
Sunny SharmaPosted Oct 24, 2013, 2:28 AM
You can NOT do that.
It completely depends on your browser setting if it saves the download files automatically to a predefined folder or it asks you every time. you can not save it from server side. It would be a security breach. Just imagine, What if I save a file without your knowledge in your any drive as it may contain harmful contents. Hope you understand now.
Happy Learning :)
Cheers !!