Hello community
I'm having problems in downloading files from a grid, i saw some solutions, all very similar, and but none solve my problem, i guess there must be some small mistake from my own. Can you help me?
I'm using layers architecture in Telerik ASP.NET ajax
//ACSX User Control
<telerik:GridTemplateColumn DataField="FileContent" HeaderText="Download" SortExpression="FileContent" UniqueName="FileContent" FilterControlAltText="Filter FileContent column"> <ItemTemplate> <asp:LinkButton runat="server" ID="lnkDownload" Text="Download" CommandName="download_file" CommandArgument='<%# Eval("Ficheiro") %>' OnClick="link1_Click"> </asp:LinkButton> </ItemTemplate> </telerik:GridTemplateColumn>
//Acsx.cs
protected void gvTimesheets_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { if (e.CommandName == "download_file") { GridDataItem item = (GridDataItem)e.Item; var itemIndex = e.CommandArgument; } protected void link1_Click(object sender, EventArgs e) { var model = listagembll.GetFileByID(ID); if (model.FileContent != null) { Response.Clear(); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Type", "Application/octet-stream"); Response.AddHeader("Content-Length", model.FileContent.Length.ToString()); Response.AddHeader("Content-Disposition", "inline; ficheiro=" + model.Ficheiro + model.FileTipo); // inline ou attachment Response.BinaryWrite(model.FileContent); Response.Flush(); Response.End(); } } }
//BLL GetFilebyID
public ListagemTimesheet GetFileByID(int ID) { using (GestaoProjectosEntities lt = new GestaoProjectosEntities()) { return lt.ListagemTimesheets.FirstOrDefault(a => a.ID == ID); } }