Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET file
I have this code written to export data to excel in a click event. The export works fine except that the page is rendered blank on this button click.
 
Can somebody tell me what I am missing in this code..??
 
protected void btnExportPDF_Click(object sender, EventArgs e)
        {
 
            if (!string.IsNullOrEmpty(hndPdfpath.Value))
            {
                // This is an important header part that informs the client to download this file.
                Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(hndPdfpath.Value));
                FileInfo flnInfo = new FileInfo(hndPdfpath.Value.Trim());
                if (flnInfo.Extension.ToLower() == ".xlsx" || flnInfo.Extension.ToLower() == ".xls")
                {
                    Response.ContentType = "application/Excel";
                }
                else
                {
                    Response.ContentType = "Application/pdf";
                }
                //Write the file directly to the HTTP content output stream.
                Response.WriteFile(hndPdfpath.Value);
            }
        }
 
Posted 3-Jun-13 2:50am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hello,
For downloading file please use
public void DownloadFile(string filePath)
{
..
}
from following link
ASP.NET File Upload with Progress Bar[^]
Thanks,
  Permalink  
Comments
aspnet_regiis -I at 3-Jun-13 10:25am
   
Thank you for your efforts. But this did not work for me.. The page is still rendered blank

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100