<ext:button id="DownLoad"runat="Server"text="download QR code"Width=" -"height=" *"AutoPostBack="false"> <DirectEvents> <click onevent="Download_click"> </Click> </DirectEvents></ext:Button>
protected void Download_click (object sender, Directeventargs e) { WriteFile ("/images/1.jpg ");}
Public voidWriteFile (stringFilePath) { Try { string_pre_path =FilePath; FilePath=Server.MapPath (FilePath); if(File.exists (FilePath)) {FileInfo Info=NewFileInfo (FilePath); Response.Clear (); Response.clearcontent (); Response.ClearHeaders (); Response.AddHeader ("content-disposition","attachment;filename="+System.IO.Path.GetFileName (FilePath)); Response.AddHeader ("Content-length", Info. Length.tostring ()); Response.AddHeader ("content-transfer-encoding","binary"); Response.ContentType="Application/octet-stream"; Response.ContentEncoding= System.Text.Encoding.GetEncoding ("gb2312"); Response.WriteFile (info. FullName); Response.Flush (); Response.End (); } } Catch(System.Threading.ThreadAbortException ex0) {}Catch(Exception ex1) {}finally{HttpContext.Current.Response.Close (); }}
If using the above code will be reported 200 error, but on the button plus one will be able to run normally, very inexplicable, 1.2 version.
<ext:fileuploadfield id="fileUpload" runat="server " buttononly="true" emptytext=" upload logo" ButtonText=""></ext:FileUploadField>
<ext:button id= "DownLoad" runat= "server" text= "download QR Code" width= "" height= "+" autopostback= " false" > <DirectEvents> <click onevent= "Download_click" > </Click> </directevents ></ext:Button>
Extjs.net button click to download JPG image