Download compressed files using jquery Ajax requests

Source: Internet
Author: User

Using third-party components: Icsharpcode.sharpziplib

Bind a Click event to a button

Background processing:

1  PublicActionResult Downzip (stringIDs)2         {3             if(string. IsNullOrEmpty (IDS))4                 returnContent ("Please select the data you want to manipulate");5 6             varIdarr =IDs. Split (Constant.SEPARATOR.ToCharArray (), stringsplitoptions.removeemptyentries);7 8             #region9FileStream fs =NULL;Ten             byte[] buffer =NULL; One             stringPath = Server.MapPath ("/upload/resource/compressed package. zip"); A              -             using(ZipFile file =zipfile.create (path)) -             { the file. BeginUpdate (); -  -                 //With this name formatter, you can do some processing of the file name inside. By default, the relevant folder is created automatically based on the path of the file in the zip.  -File. Nametransform =Newmynametransfom ();  +  -                 foreach(varIdinchIdarr) +                 { A                     varModel =NewBLL. APPRESOURCEBLL (). Getmodel (Convert.ToInt32 (ID)); at file. ADD (Server.MapPath (model. Path)); -                 }                 -  - file.commitupdate ();  -             } -FS =NewFileStream (path, filemode.open); inBuffer =New byte[FS. Length]; -Fs. Position =0; toFs. Read (Buffer,0, buffer. Length); + FS. Close (); -Response.Charset ="UTF-8"; theResponse.Buffer =false; *response.contentencoding = System.Text.Encoding.GetEncoding ("UTF-8"); $Response.ContentType ="Application/octet-stream";Panax NotoginsengResponse.AddHeader ("content-disposition","attachment; filename= compressed package. zip"); - response.binarywrite (buffer); the Response.Flush (); + Response.End (); A             return NewEmptyresult (); the             #endregion             +}

Front desk:

1 functiondownzipevent () {2         if($ (". checkall:checked"). Size () < 1) {3$.dialog.alert (' Please select Download file! ‘);4             return false;5         }6         varids = ";7$.each ($ (". checkall:checked"),function () {8IDS + = $ ( This). attr (' typeid ') + ', ';9         })Ten  One         varForm = $ ("<form>"); AForm.attr ("Style", "Display:none"); -Form.attr ("Target", "" "); -Form.attr ("Method", "POST"); theForm.attr ("Action", "/appmanage/appresource/downzip"); -         varINPUT1 = $ ("<input>"); -Input1.attr ("type", "hidden"); -Input1.attr ("name", "IDs"); +Input1.attr ("Value", IDS); -$ ("Body"). append (form); + form.append (INPUT1); A form.submit (); at Form.remove (); -}

Reference: http://blog.csdn.net/kongwei521/article/details/51167903

Http://www.jb51.net/article/74867.htm

Http://www.cnblogs.com/kissdodog/p/3525295.html

Download compressed files using jquery Ajax requests

Related Article

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.