All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
心得:PHP对文本数据库的五大基本操作方法_php资料_编程技术
如何在.NET中访问MySQL数据库_[Asp.Net教程]
ASP.NET自动识别GB2312与UTF-8编码的文件_.net资料_编程技术
.net下访问Access数据库需要注意的问题_[Asp.Net教程]
PHPUnit袖珍指南之PHPUnit的目的_php资料_编程技术
asp.net2.0网站语法之ASP.NET 2.0服务器语法
利用.NET绘图技术制作水晶按钮控件_.net资料_编程技术
ASP.NET如何存取SQL,Server数据库图_[Asp.Net教程]
如何利用.NET,Framework使用RSS,feed_.net资料_编程技术
Asp.Net中动态页面转静态页面_[Asp.Net教程]
Reading number is top 10 pictures
A beautiful girl to bud3
Average female college students3
来几张有特色的图片
NeedWallpaper10
移民小国也实惠1
乳娘帕梅拉安德森3
Azusa Yamamoto2
Players in the eyes of a perfect love2
美女当网吧管理员的悲剧
Catch prostitution woman in China
Download software ranking
Tram sex maniac 2 (H) rar bag2
网络管理员第三版
Unix video tutorial8
C++教程第四版
Boxer vs Yellow3
Unix video tutorial19
网络管理员第三版
C#与.NET技术平台实战演练
The king of fighters 97(Mobile phone games-apk)
电车之狼R
归海一刀 published in(发表于) 2014/1/30 1:22:50 Edit(编辑)
asp.net用代码压缩服务器上文件夹或文件_[Asp.Net教程]

asp.net用代码压缩服务器上文件夹或文件_[Asp.Net教程]

asp.net用代码压缩服务器上文件夹或文件_[Asp.Net教程]
实现过程

1)先引用 ICSharpCode.SharpZipLib.dll;

2).cs文件引入

using System.IO;
using System.Text;

using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;

3)代码

#region 下列代码为压缩并下载代码
ZipOutputStream zos = null;
String strBaseDir = "";

void dlZipDir(string strPath, string strFileName)
{
MemoryStream ms = null;
Response.ContentType = "application/octet-stream";
strFileName = HttpUtility.UrlEncode(strFileName).Replace(’+’, ’ ’);
Response.AddHeader("Content-Disposition", "attachment; filename=" + strFileName + ".zip");
ms = new MemoryStream();
zos = new ZipOutputStream(ms);
strBaseDir = strPath + "\\";
addZipEntry(strBaseDir);
zos.Finish();
zos.Close();
Response.Clear();
Response.BinaryWrite(ms.ToArray());
Response.End();
}

void addZipEntry(string PathStr)
{
DirectoryInfo di = new DirectoryInfo(PathStr);
foreach (DirectoryInfo item in di.GetDirectories())
{
addZipEntry(item.FullName);
}
foreach (FileInfo item in di.GetFiles())
{
FileStream fs = File.OpenRead(item.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string strEntryName = item.FullName.Replace(strBaseDir, "");
ZipEntry entry = new ZipEntry(strEntryName);
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
fs.Close();
}
}

PRotected void Button2_Click(object sender, EventArgs e)
{
string userPath ="D:\\华海实训(hohisoft.com)各级账号和密码";

dlZipDir(userPath, "华海实训(hohisoft.com)服务账号");
}

#endregion


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.