如何将文件夹转换为zip.在asp经典文件 [英] How to convert folder to zip. file in asp classic
本文介绍了如何将文件夹转换为zip.在asp经典文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都可以帮助我将经典ASP中的文件夹转换为zip文件吗.
Can any one help me in how to convert folder to zip file in classic asp.
<%
Dim objZip
Response.write("new")
Set objZip = Server.CreateObject("Scripting.FileSystemObject")
Response.write("yahoo")
objZip.Pack "C:\inetpub\wwwroot\NewZIp\Images\SMM.JPEG", "C:\inetpub\wwwroot\NewZIp\Images.zip"
objZip.Pack "C:\inetpub\wwwroot\NewZIp\Images\IMS.JPEG", "C:\inetpub\wwwroot\NewZIp\Images.zip"
Set objZip = Nothing
%>
我正在使用此代码将文件夹转换为zip
I am using this one code for convert folder to zip
推荐答案
可以使用C#在asp.net中轻松完成此操作.以下代码将帮助您压缩文件夹.
This can be easily done in asp.net using C#. Following code will help you out to zip a folder.
using System;
using System.IO;
using System.IO.Packaging;
namespace ZipSample
{
class Program
{
static void Main(string[] args)
{
AddFileToZip("Output.zip", @"C:\Windows\ABC.exe");
AddFileToZip("Output.zip", @"C:\Windows\System32\DEF.exe");
}
private const long BUFFER_SIZE = 4096;
private static void AddFileToZip(string zipFilename, string fileToAdd)
{
using (Package zip = System.IO.Packaging.Package.Open(zipFilename, FileMode.OpenOrCreate))
{
string destFilename = ".\\" + Path.GetFileName(fileToAdd);
Uri uri = PackUriHelper.CreatePartUri(new Uri(destFilename, UriKind.Relative));
if (zip.PartExists(uri))
{
zip.DeletePart(uri);
}
PackagePart part = zip.CreatePart(uri, "",CompressionOption.Normal);
using (FileStream fileStream = new FileStream(fileToAdd, FileMode.Open, FileAccess.Read))
{
using (Stream dest = part.GetStream())
{
CopyStream(fileStream, dest);
}
}
}
}
private static void CopyStream(System.IO.FileStream inputStream, System.IO.Stream outputStream)
{
long bufferSize = inputStream.Length < BUFFER_SIZE ? inputStream.Length : BUFFER_SIZE;
byte[] buffer = new byte[bufferSize];
int bytesRead = 0;
long bytesWritten = 0;
while ((bytesRead = inputStream.Read(buffer, 0, buffer.Length)) != 0)
{
outputStream.Write(buffer, 0, bytesRead);
bytesWritten += bufferSize;
}
}
}
}
这篇关于如何将文件夹转换为zip.在asp经典文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文