如何在asp.net中创建zip文件

如何在asp.net中创建zip文件,asp.net,Asp.net,我需要从文件夹中创建zip文件,路径: D:\Nagaraj\New Project Read Document\TCBILPOS\TCBILPOS\TCBILPOS\FileBuild\HOST 在该主机文件夹中有7txt文件 我想在上面的文件夹中创建zip文件HOST.zip: D:\Nagaraj\New Project Read Document\TCBILPOS\TCBILPOS\TCBILPOS\FileBuild 提前感谢。现在使用asp.net和c#可以很容易地完成这项工作

我需要从文件夹中创建zip文件,路径:

D:\Nagaraj\New Project Read Document\TCBILPOS\TCBILPOS\TCBILPOS\FileBuild\HOST
在该主机文件夹中有
7
txt文件

我想在上面的文件夹中创建zip文件
HOST.zip

D:\Nagaraj\New Project Read Document\TCBILPOS\TCBILPOS\TCBILPOS\FileBuild

提前感谢。

现在使用asp.net和c#可以很容易地完成这项工作

以下是使用System.IO.Packaging library的示例:


现在使用asp.net和c#可以很容易地完成这项工作

以下是使用System.IO.Packaging library的示例:

我在我们自己的项目中使用过

using (ZipFile zip = new ZipFile())
 {
     // add this map file into the "images" directory in the zip archive
     zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
     // add the report into a different directory in the archive
     zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
     zip.AddFile("ReadMe.txt");
     zip.Save("MyZipFile.zip");
 }
我在我们自己的项目中使用过这个

using (ZipFile zip = new ZipFile())
 {
     // add this map file into the "images" directory in the zip archive
     zip.AddFile("c:\\images\\personal\\7440-N49th.png", "images");
     // add the report into a different directory in the archive
     zip.AddFile("c:\\Reports\\2008-Regional-Sales-Report.pdf", "files");
     zip.AddFile("ReadMe.txt");
     zip.Save("MyZipFile.zip");
 }

最流行的第三方库之一(可能是因为它是免费的)是SharpZipLib:

最流行的第三方库之一(可能是因为它是免费的)是SharpZipLib:

公共类Ziper
{
公共静态字符串MapPathReverse(字符串fullServerPath)
{
返回@“~\”+fullServerPath.Replace(HttpContext.Current.Request.PhysicalApplicationPath,String.Empty);
}
公共静态void Zip(HttpResponse响应,HttpServerUtility服务器,字符串[]路径)
{
Response.Clear();
Response.BufferOutput=false;//false=stream立即
System.Web.HttpContext c=System.Web.HttpContext.Current;
//String ReadmeText=String.Format(“README.TXT\n\nHello!\n\n”+
//“这是自述文件的文本。”);
string archiveName=string.Format(“archive-{0}.zip”,
DateTime.Now.ToString(“yyyy-MMM-dd-hhmms”);
Response.ContentType=“应用程序/zip”;
Response.AddHeader(“内容处置”、“文件名=“+archiveName”);
var path=Server.MapPath(@../Images/TempFile/TempFile“+DateTime.Now.Ticks);
if(Directory.Exists(path)==false)
CreateDirectory(路径);
var-pathzipfile=Server.MapPath(@../Images/TempFile/zip戡“+DateTime.Now.Ticks+.zip”);
for(int i=0;i
公共类Ziper
{
公共静态字符串MapPathReverse(字符串fullServerPath)
{
返回@“~\”+fullServerPath.Replace(HttpContext.Current.Request.PhysicalApplicationPath,String.Empty);
}
公共静态void Zip(HttpResponse响应,HttpServerUtility服务器,字符串[]路径)
{
Response.Clear();
Response.BufferOutput=false;//false=stream立即
System.Web.HttpContext c=System.Web.HttpContext.Current;
//String ReadmeText=String.Format(“README.TXT\n\nHello!\n\n”+
//“这是自述文件的文本。”);
string archiveName=string.Format(“archive-{0}.zip”,
DateTime.Now.ToString(“yyyy-MMM-dd-hhmms”);
Response.ContentType=“应用程序/zip”;
Response.AddHeader(“内容处置”、“文件名=“+archiveName”);
var path=Server.MapPath(@../Images/TempFile/TempFile“+DateTime.Now.Ticks);
if(Directory.Exists(path)==false)
CreateDirectory(路径);
var-pathzipfile=Server.MapPath(@../Images/TempFile/zip戡“+DateTime.Now.Ticks+.zip”);
for(int i=0;i
我使用的是.Net framework 2.0。那么,为什么不使用System.IO.0或更高版本呢?有什么能阻止你吗?至少要有一个VisualStudio2010的拷贝,这将是一个巨大的飞跃。VS11处于测试阶段,即将发布。随着时间的推移和技术的进步,使用7年历史的IDE将变得越来越困难。我使用的是.Net framework 2.0。因此,使用System.IO.0,为什么不使用.Net 3.0或更高版本?有什么能阻止你吗?至少要有一个VisualStudio2010的拷贝,这将是一个巨大的飞跃。VS11处于测试阶段,即将发布。随着时间的推移和技术的进步,使用一个已经有7年历史的IDE将变得越来越困难。您已经问了9个问题,但没有接受一个答案。StackOverflow社区不是这样工作的。请在该评分的地方评分。你已经问了9个问题,但没有接受一个答案。StackOverflow社区不是这样工作的。请在该赊账的地方赊账。