ASP.NET에서 내 데이터베이스에서 파일을 다운로드하는 스크립트를 만듭니다. 다운로드 버튼을 클릭하면 다운로드로드 파일은 내 다운로드 버튼의 페이지 이름과 함께 제목이되며 파일을 업로드 할 때 원래 저장했던 .docx 파일 대신 .aspx 파일로 저장됩니다.ASP.NET 다운로드 스크립트가 현재 페이지 파일을 다운로드 파일로로드 중입니다.
이 문제를 해결하려면 지원이 필요합니다.
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 "";
}
}
* 디버깅 도움말 ("이 코드가 작동하지 않는 이유는 무엇입니까?")에는 원하는 동작, 특정 문제 또는 오류 및 질문 자체에서 재현하는 데 필요한 가장 짧은 코드가 포함되어야합니다. 명확한 문제 성명이없는 질문은 다른 독자에게 유용하지 않습니다. * [mcve] –
이 질문은 이미 많은 질문을 받았기 때문에 쉽게 대답 할 수있었습니다. http://stackoverflow.com/search?q=how+ to + download + file + asp.net –