It turns out that during the development of our project (the files are stored in the database), the downloaded files are written in the form of http headers. As follows Response.Clear();
Response.Buffer = false;
Response.AppendHeader("Content-Disposition","attachment;filename="+HttpUtility.UrlEncode(fileWJNR.Rows[0]["WJM"].ToString(),System.Text.Encoding.UTF8));
Response.BinaryWrite(byte stream);
Response.End();
However, after the project is deployed, when the user browses in IE6.0, it will be intercepted and closed and exited. At that time, my colleague used a pop-up form, and then "click to download" in the pop-up form, so that it would not be intercepted.
I tried a more direct solution, which is to first generate a temporary file when clicking, and then link to the temporary file, that is, a file download or open dialog box will pop up. The code is very simple:
string fileName = "file name" //use file id
string tempFilePath = Request.PhysicalPath;
tempFilePath = tempFilePath.Substring(0,tempFilePath.LastIndexOf("\"));
tempFilePath += " \temp\ " + fileName;
FileStream file = new FileStream(tempFilePath,FileMode.OpenOrCreate,FileAccess.ReadWrite);
try
{
byte[] docBody = (byte[])fileWJNR.Rows[0]["WJNR"]; //Conversion
file.Write(docBody, 0, docBody.Length);
file.Close();
Response.Redirect("temp\" + fileName);
}
catch
{
file.Close();
}