用ASP.Net实现在线压缩和解压缩(2)_.Net教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:Asp.net Ajax--Calendar控件使用
简介 Calendar控件是一个很简单的控件,主要用来在页面中提供日历的选择,其实现在已经有很多用javascript写的日历控件,但是Canlendar日历控件能够让我们更快速地来实现这种效果,只需要进行

// ---------------------------------------------
// 2. UnZipClass.cs
// ---------------------------------------------

using System;
using System.IO;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;
using ICSharpCode.SharpZipLib.BZip2;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;

namespace WebZipUnzip
{
public class UnZipClass
{
/// <summary>
/// 解压文件
/// </summary>
/// <param name="args">包含要解压的文件名和要解压到的目录名数组</param>
public void UnZip(string[] args)
{
ZipInputStream s = new ZipInputStream(File.OpenRead(args[0]));
try
{
ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(args[1]);
string fileName = Path.GetFileName(theEntry.Name);

//生成解压目录
Directory.CreateDirectory(directoryName);

if (fileName != String.Empty)
{
//解压文件到指定的目录
FileStream streamWriter = File.Create(args[1] fileName);

int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}

streamWriter.Close();
}
}
s.Close();
}
catch(Exception eu)
{
throw eu;
}
finally
{
s.Close();
}

}//end UnZip

public static bool UnZipFile(string file, string dir)
{
try
{
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
string fileFullName = Path.Combine(dir,file);
ZipInputStream s = new ZipInputStream(File.OpenRead( fileFullName ));

ZipEntry theEntry;
while ((theEntry = s.GetNextEntry()) != null)
{
string directoryName = Path.GetDirectoryName(theEntry.Name);
string fileName = Path.GetFileName(theEntry.Name);

if (directoryName != String.Empty)
Directory.CreateDirectory( Path.Combine(dir, directoryName));

if (fileName != String.Empty)
{
FileStream streamWriter = File.Create( Path.Combine(dir,theEntry.Name) );
int size = 2048;
byte[] data = new byte[2048];
while (true)
{
size = s.Read(data, 0, data.Length);
if (size > 0)
{
streamWriter.Write(data, 0, size);
}
else
{
break;
}
}

streamWriter.Close();
}
}
s.Close();
return true;
}
catch (Exception)
{
throw;
}
}

}//end UnZipClass
}

分享:ASP.NET备份恢复SqlServer数据库
备份SqlServer数据库 核心技术: using System.Data.SqlClient; using System.IO; string SqlStr1 = "Server=(local);DataBase=master;Uid=sa;Pwd=&q

来源:模板无忧//所属分类:.Net教程/更新时间:2008-08-22
相关.Net教程