Asp.net c # compress all files and images in the directory

Source: Internet
Author: User

Asp tutorial. net c # compress all files and images in the directory
The first method gets the absolute path of the virtual path obtained from the foreground, the second method is to pass in the virtual path of the image and obtain the file under the virtual path from the data pair path, and then call file_imgzoom to compress the image method (this introduces the image virtual path and returns the successful or failed compression information).) compress images.

*/
/// <Summary>
/// Compress all images in the folder (recursive)
/// </Summary>
/// <Param name = "path"> relative path of the folder to be compressed </param>
Public static string image_zoomformdir (string path)
  {

Directoryinfo dirpath = new directoryinfo (httpcontext. current. server. mappath (path ));
Stringbuilder sb = new stringbuilder ();
If (dirpath. exists)
  {
Sb. append (zoomallimage (dirpath, path ));
  }
Return sb. tostring ();
  }

Static string zoomallimage (directoryinfo dirpath, string path)
  {
Foreach (directoryinfo d in dirpath. getdirectories ())
  {
Zoomallimage (d, path );
  }

Stringbuilder sb = new stringbuilder ();
Foreach (fileinfo f in dirpath. getfiles ())
  {
String msg = string. empty;

File_imgzoom (string. format ("{0}/{1}", path, f. name), out msg );
Sb. append (string. format ("{0},"), msg );
  }
Return sb. tostring ();
  }

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.