ASP. NET to compress the image into a zip before downloading

Source: Internet
Author: User
Tags httpcontext

This is the exported JS method function Fundaochu () {var data = "keyword=getimagelistdaochu&type=daochu&modality=" + $ (eventrow). attr ("study_date") + "&strwhere=a.registration_id=" + $ (eventrow). attr ("reg_id") + "and a.modality= '" + $ (eventrow)    . attr ("modality") + "' ORDER by Instance_number DESC"; var renamefunc = function (msg) {if (msg! = NULL && msg! = "") {//I pass a fixed address and then upload the name of the compressed package to the foreground, but             After adding the name of the zip through the fixed address and then download var name = unescape (msg);                This is when the last digit passed is 2, it proves that no file needs to be downloaded, pop up the character no image is available for download if (name.substring (name.length-1, name.length) = = "2") {            Alert (name.substring (0, name.length-1)); } else {//The data passed must be removed last, because the last one I was splicing a 1 or 2,1 is there is data can be downloaded, 2 is no data can download var newname = name                . substring (0, name.length-1); Open this zip file via a new page to download var FileURL = window.open (". /linshi/"+ newname +". zip "," _blank "," Height=0,width=0,toolbar=no,menubar=no,scrollbarS=no,resizable=no,location=no,status=no "); var FileURL = window.open ("..               /lishi "," _blank "," height=0,width=0,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no ");                Immediately close this small page fileURL.window.close ();                Fileurl.close ();                         This is the final download of the Code FileURL.document.execCommand ("SaveAs");    }                 }    }; Commonajax (Renamefunc, NULL, data);}

This is the method of image download conversion public string Getimgdaochu (HttpRequest request) {pats_dal dall = new Pats_dal (); try {string url = string.        Empty; String zipname = String.        Empty;        String tupian_url = DateTime.Now.Year.ToString () + DateTime.Now.Month.ToString () + DateTime.Now.Day.ToString (); string where = Request. params["Strwhere"].        ToString (); String type = Request. params["type"].        ToString ();        HttpContext context = HttpContext.Current; Each time you download the file will be placed in this folder and then the front desk through this address to download, so I will delete the last time the export of the folder created, and then re-create, the effect is that this folder will always have a new file,//Here is a JPEG format picture,        Because I get from the server is not a JPEG file, is a dicm file, I need to convert this DICM file to JPEG conversion, I need to temporarily store in this folder for later compression.        String weburl = "D:\\webtupian";            if (directory.exists (Weburl)) {DirectoryInfo direct = new DirectoryInfo (Weburl); Direct.        Delete (TRUE); }//This is where the zip archive is stored in string lurl = HttpContext.Current.Server.MapPath (".        /linshi ");      if (directory.exists (Lurl)) {      DirectoryInfo Direct1 = new DirectoryInfo (Lurl); Direct1.        Delete (TRUE);        } String modality = ""; if (Request. params["modality"]! = null && request. params["modality"]. ToString () = "") {modality = Request. params["modality"].        ToString ();        }//Get specific data set information for DataSet ds = Dall.getimgdaochu (where, modality);        StringBuilder html = new StringBuilder (); String zipedfile = String.        Empty;        list<byte[]> Lstfi = new list<byte[]> ();        list<string> listimage = new list<string> ();        byte[] img = NULL; if (ds! = null && ds. Tables[0].            Rows.Count > 0) {int i = 1; foreach (DataRow row in DS. Tables[0]. Rows) {context.                Response.clearcontent (); String dcm_path = row["Reference_file"]. ToString ();//This is the address of the DICM file, string share_ip = Sys_app_config. Getappconfigvalue ("dcm_share_ip");//This is the serviceThe IP address of the Zipedfile = row["patient_id").                ToString ();//This is the number of the data. String tuname = row["Patient_name"]. ToString ();//This is the name of the current data person img = DICOMUTILITY.GETJPEGFROMDCM (Dcm_path, System.Drawing.Imaging.ImageFormat.Jp                eg);//This is a byte byte that converts a dicm file into a picture format by DICM the address and IP of the file. Image imgg = Byttoimg (IMG);//This is a picture of JPEG obtained by byte byte Zipname = tupian_url + tuname + i.tostring () + "Zhang";/zip                The name of the URL = "D:\\webtupian"; if (!                Directory.Exists (URL)) {directory.createdirectory ("D:\\webtupian");//Create a new path                } String name = Tuname + i.tostring (); Imgg. Save ("D:\\webtupian" + "/" + name + ". jpeg");//Picture Saved ListImage.                ADD ("D:\\webtupian" + "/" + name + ". jpeg");//Save the path of the current picture and use it to compress the file through the path in the back zip.                i++; Imgg.            Dispose ();            }//Compressed into zip, need to download ionic dll and then reference. Zipname This is the name of the zip using(Ionic.Zip.ZipFile Zip = new Ionic.Zip.ZipFile (Zipname, Encoding.default)) {foreach (string filetozip in ListImage) {using (FileStream fs = new Fi Lestream (Filetozip, FileMode.Open, FileAccess.ReadWrite)//convert file to file stream {byte[according to path} ] buffer = new BYTE[FS. length];//convert the file into byte-byte fs. Read (buffer, 0, buffer.                        Length);                        String fileName = Filetozip.substring (filetozip.lastindexof ("\ \") + 1); Zip.                    AddEntry (fileName, buffer); }} if (! Directory.Exists (HttpContext.Current.Server.MapPath (". /linshi ")) {Directory.CreateDirectory (HttpContext.Current.Server.MapPath (". /linshi "));//Create New path} zip. Save (HttpContext.Current.Server.MapPath (".            /linshi/"+ zipname +". zip ")); }//In order to prevent garbled, the data encapsulated a bit, to the front desk with unescape () analysis can beto the.            Return Microsoft.JScript.GlobalObject.escape (Zipname + "1");//Returns the name of the zip and the concatenation of the string in which the data can be exported} else { Return "The person currently has no pictures to export.        2 ";        }} catch (Exception e) {UTILITY.LOG.ERRORLOG.ADD (2, E, "", risconfig.pacsappver); Return "Sorry, there was an error in the system! Please check the PACS error log list for details!    2 "; }}

  

ASP. NET to compress the image into a zip before downloading

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.