I am new in Windows Application development, Trying to write code for exporting dataset to excel. I have read several examples on the internet regarding this but all are exporting the file to a location. I want to export file like in web (as an open asking to save as file).
Below is my code for the web app, what changes we need to run it on a window?
DataGridView grid_records = new DataGridView();
grid_records.DataSource = dset;
//grid_records.DataBind();
Response.Clear();
Response.Buffer = true;
Response.ClearContent();
Response.ClearHeaders();
Response.Charset = "";
string FileName = "UIDAI" + DateTime.Now + ".xls";
StringWriter strwritter = new StringWriter();
HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter);
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName);
grid_records.GridLines = GridLines.Both;
grid_records.HeaderStyle.Font.Bold = true;
grid_records.RenderControl(htmltextwrtter);
Response.Write(strwritter.ToString());
//Response.End();
Response.Flush();
Response.SuppressContent = true;
HttpContext.Current.ApplicationInstance.CompleteRequest();