全国统一热线:
028-86758058
18980748058
购买流程
付款方式
常见问题
在线提问
续租服务
购物车(
0
件)
用户名:
密 码:
记住
首 页
HOME
域名注册
DOMAIN
虚拟主机
WEB HOST
成品网站超市
AUTO Site
VPS主机
VPS SERVER
云 主 机
CLOUD HOST
租用托管
SERVER
海外主机
HK HOST
代理专区
AGENT
客服中心
SERVICE
站长教程
SERVICE
欢迎光临西部数据云计算中心,我们将竭诚为您提供最优质的服务!
中文域名
域名转入
域名转出
DNS管理
动态域名
获取域名证书
域名停放
域名过户
集群主机
双线主机
基本主机
港台主机
论坛主机
Linux主机
Vip合租主机
超G型主机
ASP.net主机
Java主机
智能建站主机
网店主机
美国主机
数据库
成品网站超市
智能建站主机
集群VPS主机
国内VPS主机
香港VPS主机
美国VPS主机
云主机介绍
云主机购买
服务器租用
主机托管
常见问题
香港主机
港台主机
美国主机
国内免备案
步骤流程
代理级别
代理合同
代理模式
代理优势
在线申请
产品列表
常见问题
代理商分布图
常见问题
有问必答
跟踪提问
购买流程
产品价格
付款方式
常用软件
网站备案
续租服务
汇款确认
相关文档
联系我们
域名资讯
主机资讯
行业动态
网页制作
php教程
mysql教程
域名资讯
云计算资讯
网络编程
您当前的位置:
首页
>
网络编程
>
Net教程
asp.net SharpZipLib的压缩与解压问题
时间:2015-01-29 来源:互联网 作者:佚名
我使用SharpZipLib.dll中遇到的问题是:利用SharpZipLib压缩后生成的*.rar文件,利用其可以正常解压,但如果使用文件右击压缩生成的*.RAR文件,在解压过程中出错,具体报错信息:Wrong Local header signature: 0x21726152 ;但*.zip文件可正常解压。
具体压缩、解压代码实现参照网络上的代码,贴出概要代码:
复制代码
代码如下:
/// <summary>
/// 压缩文件
/// </summary>
/// <param name="sourceFilePath">源文件路径</param>
/// <param name="destinationPath">压缩文件后的保存路径</param>
/// <returns>压缩是否成功</returns>
public bool Compress(string sourceFilePath, string destinationPath)
{
try
{
string[] filenames = Directory.GetFiles(sourceFilePath);
using (ZipOutputStream zs = new ZipOutputStream(File.Create(destinationPath)))
{
zs.SetLevel(9);
byte[] buffer = new byte[4096];
foreach (string file in filenames)
{
ZipEntry entry = new ZipEntry(Path.GetFileName(file));
entry.DateTime = DateTime.Now;
zs.PutNextEntry(entry);
using (FileStream fs = File.OpenRead(file))
{
int sourceBytes;
do
{
sourceBytes = fs.Read(buffer, 0, buffer.Length);
zs.Write(buffer, 0, sourceBytes);
}
while (sourceBytes > 0);
}
}
zs.Finish();
zs.Flush();
zs.Close();
}
}
catch (Exception)
{
return false;
}
return true;
} public bool DeCompress(string sourceFilePath, string destinationPath)
{
try
{
using (ZipInputStream zs = new ZipInputStream(File.OpenRead(sourceFilePath)))
{
ZipEntry entry = null;
//解压缩*.rar文件运行至此处出错:Wrong Local header signature: 0x21726152,解压*.zip文件不出错
while ((entry = zs.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(entry.Name);
string fileName = Path.GetFileName(entry.Name);
if (!string.IsNullOrEmpty(fileName))
{
using (FileStream streamWriter = File.Create(destinationPath + entry.Name))
{
int size = 2048;
byte[] data = new byte[size];
while (true)
{
size = zs.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}
}
}
}
}
}
catch (System.Exception)
{
return false;
}
return true;
}
如果需解压*.rar的压缩文件在网络也可以找到相关的实现代码,概要代码:
复制代码
代码如下:
public bool DeCompressRAR(string sourceFilePath, string destinationPath)
{
try
{
string SeverDir = @"D:\Program Files\WinRAR";//rar.exe的要目录
Process ProcessDecompression = new Process();
ProcessDecompression.StartInfo.FileName = SeverDir + "\\rar.exe";
Directory.CreateDirectory(sourceFilePath);
ProcessDecompression.StartInfo.Arguments = " X " + sourceFilePath + " " + destinationPath;
ProcessDecompression.Start();
while (!ProcessDecompression.HasExited)
{
//nothing to do here.
}
return true;
}
catch (System.Exception)
{
return false;
}
}
我本想利用FileUpload控件将上传的压缩文件解压后保存至相对应的目录并更新
数据库
文件目录,后发现一些较好的用于上传的开源软件:如NeatUpload,SWFUpload可以较方便的实现我的需求,遂没有过多纠缠于SharpZipLib,可能关于SharpZipLib的压缩与解压有其它用法,不能被我误导,以上代码是从网络上整合出来的,因为它太过于重复和散乱。
来顶一下
返回首页
推荐资讯
asp.net Javascript 的几种写法与提
Vs2008环境,上图为先Common.js 复制代码 代码如下: var Com
测试控制台使用方法
基本条件 熟悉asp.net环境 对Discuz!NT论坛有所了解 操作步骤
相关文章
asp.net 中国身份证号码验证代码 非正则
asp.net url重写后页面回传问题
asp.net 实现动态显示当前时间(不用javascript不考虑开
asp.net Javascript 的几种写法与提示
asp.net与Discuz!NT整合集成实例教程
Discuz!NT 3与asp.net 整合的实例教程
asp.net 结合YUI 3.0小示例
ASP.NET MVC学习笔记
asp.net 取消缓存相关问题说明
asp.net sql 数据库处理函数命令
栏目更新
栏目热门
返回首页
关于我们
联系我们
付款方式
价格总览
资讯中心
友情链接
媒体关注
有问必答
投诉建议
网站备案
《中华人民共和国增值电信业务经营许可证》编号:川B2-20080058号
官方网址:
xibushuju.com
西部数据
Copyright © 2002~2015
天府快车
版权所有
电话总机:
028-86758058
(50线) 传真:
028-86758058