ASP.Net C#| Download File


  ASP.Net C#| Download File



Code - Method 1:

try
            {
                string strURL = "/Files/filename.pdf";
                WebClient req = new WebClient();
                HttpResponse response = HttpContext.Current.Response;
                response.Clear();
                response.ClearContent();
                response.ClearHeaders();
                response.Buffer = true;
                response.AddHeader("Content-Disposition""attachment;filename=\"" + strURL + "\"");
                byte[] data = req.DownloadData(Server.MapPath(strURL));
                response.BinaryWrite(data);
                response.End();
            }
            catch (Exception ex)
            {
            }

Code - Method 2:

try
            {
                Response.ContentType = "Application/pdf";
           Response.AppendHeader("Content-Disposition""attachment; filename=TechnicalDocumentforLogin.pdf");
           Response.TransmitFile(Server.MapPath("~/Files/filename.pdf"));
           Response.End();
            }
            catch (Exception ex)
            {
            }

  Enjoy !!!

:)

 

No comments:

Post a Comment