ASP. NET implementation Base64 file stream download PDF

Source: Internet
Author: User
Tags base64

Because the business needs to call the interface gets the Base64 file stream needs to be provided to the customer to download the PDF document

Source part of the Internet, the specific address forgotten.

 Base64 file stream byte[] buffer = convert.frombase64string (decodedstring);            System.IO.Stream IStream = new System.IO.MemoryStream (buffer);                try {int length;                Long dataToRead;                string filename = sn + ". pdf";//Saved file name dataToRead = istream.length;                Response.Clear ();                Response.ClearHeaders ();                Response.clearcontent (); Response.ContentType = "Application/pdf"; File type Response.AddHeader ("Content-length", datatoread.tostring ());//Add file length to show progress Respo Nse. AddHeader ("Content-disposition", "attachment;                Filename= "+ httputility.urlencode (filename, System.Text.Encoding.UTF8));                        while (dataToRead > 0) {if (response.isclientconnected) {                        Length = istream.read (buffer, 0, 10000); Response.OutputStream.WrITE (buffer, 0, length);                        Response.Flush ();                        Buffer = new byte[10000];                    dataToRead = Datatoread-length;                    } else {datatoread =-1;             }}} catch (Exception ex) {Response.Write ("An error occurred while downloading the file!"); } finally {if (IStream! = null) {ISTR Eam.                Close ();                }//End response, otherwise it will cause the Web page content to be output to a file, and the file cannot be opened Response.Flush ();            Response.End (); }

  

ASP. NET implementation Base64 file stream download PDF

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.