我錯過了這段代碼中的內容嗎?因爲我測試它時我得到的文件類型爲「文件」而不是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
您有一個SQL注入漏洞。 – SLaks