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