天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

asp.net SharpZipLib的壓縮與解壓問題

我使用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 + "http://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的壓縮與解壓有其它用法,不能被我誤導,以上代碼是從網絡上整合出來的,因為它太過于重復和散亂。

AspNet技術asp.net SharpZipLib的壓縮與解壓問題,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 青青草原91| 1300部真实小Y女视频合集 | 日本免费一区二区三区四区五六区 | 日本美女bb | 狠狠撸亚洲视频 | 一区三区不卡高清影视 | 我的美女房东未删减版免费观看 | 一边摸一边桶一边脱免费 | 国产亚洲精品久久久久久入口 | 欧美一级久久久久久久久大 | 2021精品高清卡1卡2卡3麻豆 | 爆乳啪啪无码成人二区亚洲欧美 | YELLOW视频直播在线观看 | 欧美日韩国产码在线 | 大陆女人内谢69XXXORG | 无敌在线视频观看免费 | 韩日午夜在线资源一区二区 | 国产成人无码精品久久久按摩 | 亚洲精品一线二线三线无人区 | 最新果冻传媒在线观看免费版 | 快播免费电影 | 国产 亚洲 中文字幕 久久网 | 电影内射视频免费观看 | 日本不卡一二三 | 黄页网站18以下勿看免费 | 久久青青热| 人妻免费视频公开上传 | 性饥渴姓交HDSEX | 2022年国产精品久久久久 | 口工漫画r18全彩啪啪 | 亚洲AV无码影院在线播放 | 亚洲国产精品无码AV久久久 | 亚洲麻豆精品成人A在线观看 | 琪琪伦伦影院理论片 | 丝瓜涩涩屋黄瓜香蕉丝瓜 | 0951影音在线 | 亚洲不卡高清免v无码屋 | 韩国甜性涩爱 | 毛片视频大全 | 日本美女毛茸茸 | 国产亚洲精品网站在线视频 |