可以支持文件夹压缩啊,不知你是怎么调用的,我把文件\Zip\ZipConstants.cs 中的内容改成(如下)就支持中文文件名了,原来中文解压后会变成下划线了。
------------------------------------------------------------
public static string ConvertToString(byte[] data)
{
return Encoding.GetEncoding(936).GetString(data,0, data.Length);
}public static byte[] ConvertToArray(string str)
{
return Encoding.GetEncoding(936).GetBytes(str);
}
------------------------------------------------------------
public static string ConvertToString(byte[] data)
{
return Encoding.GetEncoding(936).GetString(data,0, data.Length);
}public static byte[] ConvertToArray(string str)
{
return Encoding.GetEncoding(936).GetBytes(str);
}
解决方案 »
- C#中的名称空间究竟是什么含义?
- 水晶报表如何在设计阶段就预定页数呢
- 省市区县联动问题:如何把前台选到的值传给BOX?
- 水晶报表2008加载速度的问题
- 请问如何从一张表中提取出一个字段的全部数据
- C#发送串口数据格式问题
- 请问C#怎么与Oracle进行连接,怎么写连接字符串?
- linq to sql绑定到datagridview控件的问题
- 告别朋友们一段日子,我要去闭门思过了!
- 我连接数据库时,提示这个错误:sa登录失败,未与信任的SERVER\DADI(服务器上的数据库)联接相关联,到底是错在什么地方?
- 怎么往Crystal Reports报表里传参数!急…………
- 求救,如何获得数据库的存储错误?
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;using ICSharpCode.SharpZipLib.Zip;
using System.IO;namespace CSharpZipFileTest
{
/// <summary>
/// Summary description for index.
/// </summary>
public class index : System.Web.UI.Page
{
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
this.dlZipDir(@"D:\dir","zipTest"); } #region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion ZipOutputStream zos=null;
String strBaseDir="";
private 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();
}
private 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();
}
}
}
}
你试试。
看看这编文章吧