2017-06-04 22 views
0

我錯過了這段代碼中的內容嗎?因爲我測試它時我得到的文件類型爲「文件」而不是PDF。用戶從數據庫下載後需要幫助來更改文件格式

protected void Button1_Click(object sender, EventArgs e) 
{ 
    SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"].ConnectionString); 
    conn.Open(); 
    string pdffile = "select pdf from users where ID='" + TextBoxLic.Text + "'"; 
    SqlCommand pdfcom = new SqlCommand(pdffile, conn); 
    SqlDataReader reader = pdfcom.ExecuteReader(); 
    if (reader.Read()) 
    { 
     Byte[] pdfData = (byte[])reader.GetValue(0); 
     Response.ContentType = "Application/pdf";    
     Response.AppendHeader("content-disposition", "attachment; filename=" + TextBoxLic.Text); 
     Response.BinaryWrite(pdfData); 
     Response.End(); 
     conn.Close(); 
    } 
} 

https://i.gyazo.com/8eb75d4e55bed17155690531841d80c7.png

+2

您有一個SQL注入漏洞。 – SLaks

回答

0

您需要的Content-Type頭設置爲application/pdf

+0

我做了但仍然沒有改變:( – Mute

+0

MIME類型是區分大小寫的,應該是全小寫的 – SLaks

+0

類型文件沒有改變:( – Mute