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

asp.net SharpZipLib的壓縮與解壓?jiǎn)栴}

我使用SharpZipLib.dll中遇到的問(wèn)題是:利用SharpZipLib壓縮后生成的*.rar文件,利用其可以正常解壓,但如果使用文件右擊壓縮生成的*.RAR文件,在解壓過(guò)程中出錯(cuò),具體報(bào)錯(cuò)信息:Wrong Local header signature: 0x21726152 ;但*.zip文件可正常解壓。
具體壓縮、解壓代碼實(shí)現(xiàn)參照網(wǎng)絡(luò)上的代碼,貼出概要代碼:
復(fù)制代碼 代碼如下:
/// <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文件運(yùn)行至此處出錯(cuò):Wrong Local header signature: 0x21726152,解壓*.zip文件不出錯(cuò)
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的壓縮文件在網(wǎng)絡(luò)也可以找到相關(guān)的實(shí)現(xiàn)代碼,概要代碼:
復(fù)制代碼 代碼如下:
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控件將上傳的壓縮文件解壓后保存至相對(duì)應(yīng)的目錄并更新數(shù)據(jù)庫(kù)文件目錄,后發(fā)現(xiàn)一些較好的用于上傳的開(kāi)源軟件:如NeatUpload,SWFUpload可以較方便的實(shí)現(xiàn)我的需求,遂沒(méi)有過(guò)多糾纏于SharpZipLib,可能關(guān)于SharpZipLib的壓縮與解壓有其它用法,不能被我誤導(dǎo),以上代碼是從網(wǎng)絡(luò)上整合出來(lái)的,因?yàn)樗^(guò)于重復(fù)和散亂。

AspNet技術(shù)asp.net SharpZipLib的壓縮與解壓?jiǎn)栴},轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产成人精品精品欧美 | 国产成人无码一区AV在线观看 | 四虎永久在线精品国产 | 蜜桃久久久亚洲精品成人 | 国产欧美日韩精品a在线观看高清 | 囯产免费久久久久久国产免费 | 黄色三级视频网站 | 一本久道视频无线视频 | 久久免费高清 | 皮皮在线精品亚洲 | 999精品在线 | 色欲色香天天天综合 | 好男人资源免费观看1 | 久久久久久久国产精品视频 | 男同志video最新猛男 | 动漫美女无衣 | 国产精品免费一区二区三区四区 | 国产专区亚洲欧美另类在线 | 男人国产AV天堂WWW麻豆 | 99精品国产高清自在线看超 | 国产精品久久久久婷婷五月色 | 亚洲欧美高清在线精品一区 | 午夜dj影院视频观看 | 国产免费午夜 | 大胸美女被C得嗷嗷叫动态图 | 在线黑人抽搐潮喷 | 国精产品一区一区三区有限 | 日本精品在线观看视频 | 亚洲精品国产品国语在线试看 | 国产高清视频免费在线观看 | 欧美麻豆一精品一AV一免费 | 亚洲色 图 | 国产中文欧美日韩在线 | 国内精品国内自产视频 | 国产专区亚洲欧美另类在线 | 强壮的公次次弄得我高潮韩国电影 | 高潮久久久久久久久不卡 | 欧美精品高清在线观看 | 抽插妇女疯狂视频 | av影音先锋天堂网 | 欧美 亚洲综合在线一区 |