c#压缩文件,解压文件写法
来源:互联网 发布:怎样找网络兼职 编辑:程序博客网 时间:2024/05/17 06:18
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
{
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();
}
}
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using System.IO;
压缩文件
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();
}
}
0 0
- c#压缩文件,解压文件写法
- C#压缩文件,解压文件。
- C#解压RAR压缩文件
- C#解压RAR压缩文件
- c#解压、压缩文件
- C# 解压RAR压缩文件
- C# 解压zip压缩文件
- Ubuntu压缩文件解压文件
- linux压缩文件&解压文件
- C#利用ICSharpCode.SharpZipLib.dll压缩文件和解压文件
- (转载)C#利用ICSharpCode.SharpZipLib.dll压缩文件和解压文件
- C#学习笔记之压缩文件和解压文件
- C#压缩解压RAR压缩文件
- C#压缩解压RAR压缩文件
- C# 解压及压缩文件源码
- c#解压压缩文件和文件夹
- c# 压缩文件及解压Zip
- java压缩文件和解压文件
- 开发规范
- 蓝鸥Unity开发教程之课时15 刚体
- golang中结构体的初始化方法(new方法)
- EasyUI的datagrid在IE下的缓存问题
- 快速了解RESTEasy
- c#压缩文件,解压文件写法
- Intellij IDEA【模拟http请求】
- Activity的生命周期和一些常用技巧1
- 记录自己遇到的问题(1) 乱码问题
- java多线程并发问题
- eclispe中的maven项目使用spring报java.lang.ClassNotFoundException: org.springframework.web.c
- MMORPG经济系统设计经验
- 支持移动端的仿medium图片放大预览js插件
- iOS EXC_BAD_ACCESS 问题