I'm loading data in a telerik:RadGrid, but I have one column that is not loading, which includes files (binary data).
As you can see in the image, instead of loading DB content, this column just loads System.Byte
:
Note in a above how we not only saved the file name, but ALSO saved the "mine" type. .net 4.5 (or later) has a built in function called GetMineType - you can pass it a file name, and it will produce the correct mine type.
So, in above, when you click on the "image button", then we have this code to fetch the bytes from the database, and send it to the client:
protected void cmdExcel_Click(object sender, ImageClickEventArgs e)
{
ImageButton btn = (ImageButton)sender;
GridViewRow gRow = (GridViewRow)btn.Parent.Parent;
int PKID = (int)GridView1.DataKeys[gRow.RowIndex]["ID"];
// get data from table
DataRow rstData = MyRst("SELECT FileB, FileName, MineType from tblFiles where ID = " PKID).Rows[0];
Byte[] binFile = (Byte[])rstData["FileB"];
Response.Clear();
Response.ClearContent();
Response.ClearHeaders();
Response.ContentType = rstData["MineType"].ToString();
Response.AddHeader("Content-Disposition", "inline; filename=" rstData["FileName"]);
Response.BinaryWrite(binFile);
Response.End();
}
As noted, most grids, be they gridview, list view or that telerick grid should work similar. So you don't include the bytes() data in the grid, but allow a button click, and stream down (send) the byte file to the client.