如何从 RadGridAttachmentColumn 下载二进制数据?
我的代码
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
{
GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
string fileName = args.FileName;
int attachmentId = (int)args.AttachmentKeyValues["ProjectFileId"];
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = (from type in objEntity.ProjectFiles where type.ProjectFileId == attachmentId select type).First();
string filename = objFile.FileName;
string Filetype = objFile.FileType;
byte[] binaryData = (byte[])objFile.FileData;
//byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"];
// Response.AppendHeader("Content-Disposition", "attachment; filename = "+filename);
// Response.AppendHeader("Content-Length", filename.Length.ToString());
//Response.ContentType = Filetype;
//Response.WriteFile(Server.MapPath("Uploads/"+filename));
//Response.Flush();
//Response.Close();
//Response.End();
// grdFiles.Items[0].FireCommandEvent(RadGrid.DownloadAttachmentCommandName, parameters);
Response.Clear();
Response.ContentType = Filetype;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(binaryData);
Response.End();
}
}
当我调试上传的数据转换为二进制数据并保存在数据库中时。我可以从本地客户端下载。但从服务器端下载时不起作用。
My code
protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
{
GridDownloadAttachmentCommandEventArgs args = e as GridDownloadAttachmentCommandEventArgs;
string fileName = args.FileName;
int attachmentId = (int)args.AttachmentKeyValues["ProjectFileId"];
ProTrakEntities objEntity = new ProTrakEntities();
ProjectFile objFile = (from type in objEntity.ProjectFiles where type.ProjectFileId == attachmentId select type).First();
string filename = objFile.FileName;
string Filetype = objFile.FileType;
byte[] binaryData = (byte[])objFile.FileData;
//byte[] binaryData = (byte[])data.Tables[0].Rows[0]["BinaryData"];
// Response.AppendHeader("Content-Disposition", "attachment; filename = "+filename);
// Response.AppendHeader("Content-Length", filename.Length.ToString());
//Response.ContentType = Filetype;
//Response.WriteFile(Server.MapPath("Uploads/"+filename));
//Response.Flush();
//Response.Close();
//Response.End();
// grdFiles.Items[0].FireCommandEvent(RadGrid.DownloadAttachmentCommandName, parameters);
Response.Clear();
Response.ContentType = Filetype;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
Response.BinaryWrite(binaryData);
Response.End();
}
}
When i debugging the uploaded data converted to binary data and saved in Database.I can download from local client.but not working when downloading from server side.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
添加此内容并确保唯一名称是不同的。
add this and make sure that the unique names are distinct.