I’m using this code as export to excel from gridview in local machine…..
void btn_excelClick()
{
Response.ClearContent();
Response.Buffer = true;
Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "c.xls"));
Response.ContentType = "application/vnd.ms-excel";
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
GridView2.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
My Question is: How should i modify my code so that the file is downloaded in server side when the end-user clicks on it, and a download link for the source file should pop up.
PS: My Comp is currently my server…
Rather than writing your output to the Response, write it to a file.
Ensure that the path to where you write the file is in a directory that is accessible through IIS.
Now you can just write a link to the file in the response, and set the path to this newly created file.