开发者

how to download binary data from RadGridAttachmentColumn?

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(开发者_StackOverflow社区));
               //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.


protected void grdFiles_ItemCommand(object source, GridCommandEventArgs e)
{

    if (e.CommandName == RadGrid.DownloadAttachmentCommandName)
    {
        RadAjaxManager Manager = new RadAjaxManager();
        Manager.EnableAJAX = false;
        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();
        byte[] binaryData = (byte[])objFile.FileData;
        //grdFiles.DataSource = objFile;
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("content-disposition", "attachment; filename=" + fileName);
        Response.BinaryWrite(binaryData);
        Response.Flush();
        Response.Close();
        Response.End();



    }
}

add this and make sure that the unique names are distinct.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜