PDF Download from server in c#

Last Reply 8 days ago By dharmendr

Posted 10 days ago

Hi Friends,

i have pdf in server with below link

http://10.xx.xx.32/NewCustomer/PdfDocuments/CUS04704.pdf

how to download this pdf in browser using button click event?

code which i have tried.. but not downloaded

 public  void DownloadPDFfile()
        {
           
            System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(@"~/pdfTest/CUS049217.pdf"));
            if ((file.Exists))
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                Response.AddHeader("Content-Length", file.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.TransmitFile(file.FullName);
                Response.End();
                Response.Close();
                file = null;
            }
        }

 

You are viewing reply posted by: dharmendr 8 days ago.