ASP.NET下载脚本正在加载当前页面文件作为下载文件

时间:2016-09-22 07:31:20

标签: c# asp.net

我在ASP.NET中创建了一个脚本,用于从我的数据库下载文件。当我点击下载按钮时,下载的文件是带有我的下载按钮页面名称的标题,文件保存为.aspx文件,而不是我上传时最初保存的.docx文件。< / p>

我需要你的协助才能解决这个问题。

protected void Download(object sender, EventArgs e)
{
    if (Request.QueryString["Request-Id"] != "")
    { 
        string fileName = getFileName(Convert.ToInt32(Request.QueryString["Request-Id"]));

        if (fileName != "") { 
            Response.ContentType = "Application/vnd.openxmlformats-officedocument.wordprocessingml.document";  
            Response.AppendHeader("content-deposition", "attachment/filename=\""+fileName+"\"");
            Response.TransmitFile(Server.MapPath("/Uploads/" + fileName));
            Response.End();  
        }
    }
}

protected string getFileName(int id)
{  
    string connStr = ConfigurationManager.ConnectionStrings["DbCall"].ToString();
    SqlConnection conn = new SqlConnection(connStr);

    conn.Open();
    SqlCommand command = new SqlCommand("select Conveyance_Document from Convey where Request_Id = @Id", conn);
    command.Parameters.AddWithValue("@Id", Convert.ToInt32(id));

    SqlDataReader sdr = command.ExecuteReader();

    if (sdr.Read())
    {  
        string fileName = sdr["Conveyance_Document"].ToString();
        conn.Close();
        conn.Dispose();
        return fileName;
    }
    else
    {
        conn.Close();
        conn.Dispose();
        return "";
    }
}

1 个答案:

答案 0 :(得分:0)

试试这个:

content-deposition

标题名称为 pjsua_conf_adjust_rx_level(0 /* pjsua_conf_port_id slot*/, 0.0f); //for mute the audio pjsua_conf_adjust_rx_level(0 /* pjsua_conf_port_id slot*/, 1.0f); //for unmute the audio. ,而不是$(document).ready(function() { var videos = []; $('.header-video__media').each(function(i, elem) { var mediaElement = $(elem); var mood = mediaElement.attr('data-mood'); headerVideo = new HeaderVideo({ index:i, element: '.header-video', media: '.header-video__media', playTrigger: '.header-video__play-trigger', closeTrigger: '.header-video__close-trigger', nextTrigger: '.header-video__next-trigger' }); videos.mood = mood; videos.push (headerVideo); });