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 and telerik framework
.
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 and telerik framework
ASCX 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 method to get the row in the grid:
public ListagemTimesheet GetFileByID(int ID)
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
return lt.ListagemTimesheets.FirstOrDefault(a => a.ID == ID);
}
}