从db下载文件类型var binary [英] download file type var binary from db

查看:89
本文介绍了从db下载文件类型var binary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iam使用此代码下载



下载是正确的但是下载后打开文件类型zip文件或pdf时看到此错误



.. \ jcoverflip-1.0.2.zip:存档格式未知或已损坏







iam use this code for download

download is correct but after downlaod when open file type zip file or pdf see this error

..\jcoverflip-1.0.2.zip: The archive is either in unknown format or damaged



protected void LAtt_Click(object sender, EventArgs e)
    {
        string str = String.Empty;
        Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["bakerConnectionString"].ToString());
        Cmd = new SqlCommand();
        Cmd.CommandText = "SELECT * FROM Tcomplaint where id_complaint=@id_complaint";
        Cmd.Parameters.AddWithValue("@id_complaint", int.Parse((Request.QueryString["id"].ToString())));
        Cmd.Connection = Conn;
        if (Conn.State == ConnectionState.Closed)
            Conn.Open();
        SqlDataReader reader = Cmd.ExecuteReader();
        reader.Read();
        /*  اگر خانه ای با رکورد مورد نظر پیدا کند*/
        if (reader.HasRows)
        {
            if (!reader.IsDBNull(reader.GetOrdinal("FuploadFilesname")))
                str = reader.GetString(reader.GetOrdinal("FuploadFilesname"));

            if (!reader.IsDBNull(reader.GetOrdinal("Fupload")))
            {
                //LAtt.Text = "یک فایل ارسال شده";
                Response.Clear();
                Response.Buffer = true;
                Response.ContentType = reader.GetString(reader.GetOrdinal("FContentTypeAttachFile"));
                Response.AddHeader("content-disposition", "attachment;filename=" + str);
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite((byte[])reader["Fupload"]);
                Response.Flush();
                Response.End();

            }
        }
        Conn.Close();
        Conn.Dispose();
    }

推荐答案

首先你可能错误地保存了它:这是图像的常见问题,这同样适用于任何二进制数据。

请参阅此处获取解释和解决方案:为什么我得到参数无效。我从数据库中读取图像时出现异常? [ ^ ]
The chances are that you saved it wrong in the first place: this is a common problem with images, and the same applies to any binary data.
See here for an explanation, and the solution: Why do I get a "Parameter is not valid." exception when I read an image from my database?[^]


这篇关于从db下载文件类型var binary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆