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 ();
}