asp.net(c#)中SQL Server的Blob使用错误的文件名保存

asp.net(c#)中SQL Server的Blob使用错误的文件名保存,c#,asp.net,sql-server,blob,C#,Asp.net,Sql Server,Blob,我正在尝试使用.net中的gridview来允许用户从存储在sql server表中的存储库下载文件,文件名为varbinary(max)。上传过程没有问题。问题在于检索。我在gridview中的每一行上使用一个link按钮来允许下载文件。单击“下载”链接按钮时,我会看到一个保存/打开框(IE)。但是,要保存的文件名是.aspx页面的名称,而不是表中存储的文件名 以下是linkbutton单击事件的代码: protected void lbtnDownload_Click(object

我正在尝试使用.net中的gridview来允许用户从存储在sql server表中的存储库下载文件,文件名为varbinary(max)。上传过程没有问题。问题在于检索。我在gridview中的每一行上使用一个link按钮来允许下载文件。单击“下载”链接按钮时,我会看到一个保存/打开框(IE)。但是,要保存的文件名是.aspx页面的名称,而不是表中存储的文件名

以下是linkbutton单击事件的代码:

    protected void lbtnDownload_Click(object sender, EventArgs e)
    {
        int gmsrId = int.Parse((sender as LinkButton).CommandArgument);

        byte[] bytes;
        string strFilename = String.Empty;
        string strContentType = String.Empty;

        string strConnString = dbUtilities.GetConnectionString();

        using (SqlConnection sqlCon = new SqlConnection(strConnString))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_SelectDocument";
                cmd.Connection = sqlCon;

                cmd.Parameters.AddWithValue("@intID", gmsrId);
                sqlCon.Open();

                using (SqlDataReader sdrDocument = cmd.ExecuteReader())
                {

                    sdrDocument.Read();
                    bytes = (byte[])sdrDocument["gmsr_Document"];
                    strContentType = sdrDocument["gmsr_ContentType"].ToString();
                    strFilename = sdrDocument["gmsr_Filename"].ToString();
                    lblMessage.Text = "Filename = " + strFilename;
                    sqlCon.Close();
                }

                Response.Clear();
                Response.Buffer = true;
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = strContentType;

                Response.AppendHeader("Content-Dispositon", ("attachment; filename=" + strFilename));
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();


            }
        }
    }
我对从表中存储/检索blob还不熟悉,并且已经接近将文件存储在文件系统中,但我不愿意放弃。我想我遗漏了一些小东西,但找不到。提前谢谢。

您拼错了“性格”(忘记了i)。应该是:

Response.AppendHeader("Content-Disposition", ("attachment; filename=" + strFilename));

应避免使用sp_uu前缀。它由MS保留,表示系统过程,而不是存储过程。就我个人而言,我不喜欢所有的前缀,因为它们除了不必要的击键和在列表中查找对象的困难之外,什么都没有添加。