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
Code
' OnClick="link1_Click">//Acsx.cs
C#
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
C#
public ListagemTimesheet GetFileByID(int ID)
{
using (GestaoProjectosEntities lt = new GestaoProjectosEntities())
{
return lt.ListagemTimesheets.FirstOrDefault(a => a.ID == ID);
}
}
Sachin SinghRank #66 · 26.2K reputationPosted Nov 4, 2021, 5:31 AM EDT
Harlem 98143 reputationPosted Nov 4, 2021, 12:11 PM EDT
I can´t post my full anwser because of casharpcorner error, with some changes the approach as worked.
Nevertheless, now i have big new issues
The file downloads, only with its name as content, and the page keeps loading infinitily after the download's finished.
Sachin SinghRank #66 · 26.2K reputationPosted Nov 5, 2021, 6:18 AM EDT
Harlem 98143 reputationPosted Nov 5, 2021, 7:41 AM EDT