C # implements the Download function: (data stored in the database is varbinary () type data)
Byte[] by = null; Defines a byte array to hold the number of bytes read in the database
if (dt. rows[0]["Byte"]! = NULL | | Dt. rows[0]["Byte"] = DBNull.Value)//Determine if data is found in the database
{
by= (byte[]) dt. rows[0]["Byte"]; Convert data to a byte type assign a value to by
}
Else
{
Stre. Byte = null;
Return Content ("<script>alert (' Download failed! '); location.href= '/home/index ';</script> ");
}
Response.Clear (); Clears all content output from the buffer stream
Response.ClearHeaders (); Clears all headers in the buffer stream, does not know why, does not write this sentence will display the error page
Response.Buffer = false; Set buffered output to False
Response.ContentType = "application/" + stre. Extension;
Response.AddHeader ("content-disposition", "inline; Filename= "+ stre. FileName);
Response.BinaryWrite (by);
Response.Flush (); Sends all current buffered output to the client
Response.close ();
Return Content ("<script>alert (' Download succeeded! '); location.href= '/home/index ';</script> ");
C # normal Download