Download file using asp.net

 protected void Page_Load(object sender, EventArgs e)
    {


string[] filePaths = Directory.GetFiles(Server.MapPath("~/AttatchPath/"));
            List<ListItem> files = new List<ListItem>();
            foreach (string filePath in filePaths)
            {
                files.Add(new ListItem(Path.GetFileName(filePath), filePath));
            }
}



protected void btndownload_Click(object sender, EventArgs e)
    {
       // string filePath = (sender as LinkButton).CommandArgument;
        var filePath = image.ImageUrl;
        Response.ContentType = ContentType;
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(filePath));
        Response.WriteFile(filePath);
        Response.End();
    }




 <asp:LinkButton ID="btndownload" runat="server" Text="Download" OnClick="btndownload_Click"></asp:LinkButton>

Comments

Popular posts from this blog

Create Schema Using C# Asp .Net Dynamically.

How to set Transaction and Roll Back using Entity Framework in C# Code.

How to post image in blob using Windows Azure.