C # normal Download

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.