Quantcast
Viewing all articles
Browse latest Browse all 4

Answer by Delta for How to download a file using ASP.NET

Use the below code to download the file on link button click

<asp:LinkButton ID="btnDownload" runat="server" Text="Download"            OnClick="btnDownload_OnClick" />protected void btnDownload_OnClick(object sender, EventArgs e)    {        string filename = "~/Downloads/msizap.exe";        if (filename != "")        {            string path = Server.MapPath(filename);            System.IO.FileInfo file = new System.IO.FileInfo(path);            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.WriteFile(file.FullName);                Response.End();            }            else            {                Response.Write("This file does not exist.");            }        }    }

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>