<%@ Page language="C #"%> <%//How to use//downloadfile.aspx?file= the image URL to download stringURL =HttpContext.Current.Request.Url.Query.ToLower (); //file=dddd.jpgurl = URL. Replace ("? file=",""); Response.bufferoutput=false; Response.Clear (); Response.ContentType="Application/x-msdownload"; Response.appendheader ("content-disposition","attachment; Filename="+URL); Response.ContentType="Application/octstream"; Response.CacheControl="Private"; System.IO.Stream STM=NewSystem.IO.FileStream (Server.MapPath (URL), System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); Response.appendheader ("Content-length", STM. Length.tostring ()); System.IO.BinaryReader BR=NewSystem.IO.BinaryReader (STM); byte[] bytes; for(Int64 x =0; x < (Br. Basestream.length/4096+1); X + +) {bytes= Br. Readbytes (4096); Response.BinaryWrite (bytes); System.Threading.Thread.Sleep (5);//Take a break to prevent too much bandwidth being consumed. } stm. Close (); %>
Front-End Call download
$ ("#download"). Click (function () { "downloadfile.aspx? file=""/kjzbsc/qrcode.jpg"; });
Download server image to client via browser