asp.net ¶Ô Îļþ½øÐÐѹËõ or ½âѹ£¨zip
asp.net ¶Ô Îļþ½øÐÐѹËõ or ½âѹ£¨zip£©
/// <summary>
/// ¶ÔÎļþ½øÐУ¨Ñ¹Ëõ£¬½âѹ£©
/// </summary>
public static class ZIP
{
/// <summary>ѹËõÎļþ</summary>
/// <param name="filename">filenameÉú³ÉµÄÎļþµÄÃû³Æ£¬È磺C\123\123.zip</param>
/// <param name="directory">directoryҪѹËõµÄÎļþ¼Ð·¾¶</param>
/// <returns></returns>
public static bool PackFiles(string filename, string directory)
{
try
{
directory = directory.Replace("/", "\\");
if (!directory.EndsWith("\\"))
directory += "\\";
if (!Directory.Exists(directory))
{
Directory.CreateDirectory(directory);
}
if (File.Exists(filename))
{
File.Delete(filename);
}
//ICSharpCode.SharpZipLib.Zip.ZipFile pp = new ZipFile();
//FastZip fz = new FastZip();
//fz.CreateEmptyDirectories = true;
//fz.CreateZip(filename, directory, true, "");
return true;
}
catch (Exception)
{
return false;
}
}
/// <summary>½âѹÎļþ</summary>
/// <param name="file">ѹËõÎļþµÄÃû³Æ£¬È磺C:\123\123.zip</param>
/// <param name="dir">dirÒª½âѹµÄÎļþ¼Ð·¾¶</param>
/// <returns></returns>
public static bool UnpackFiles(string file, string dir)
{
try
{
if (!File.Exists(file))
return false;
dir = dir.Replace("/", "\\");
if (!dir.EndsWith("\\"))
dir += "\\";
if (!Directory.Exists(dir))
Directory.CreateDirectory(dir);
ZipInputStream s = new ZipInputStream(File.OpenRead(file));
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(dir + directoryName);
if (fileName != String.Empty)
{
FileStream streamWriter = File.Create(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
{
Ïà¹ØÎĵµ£º
¼òÒ×¼ÆËãÆ÷
1.ÔÚÒ³ÃæÉÏ·ÅÈëTextBox¿Ø¼þºÍdropdownlist¿Ø¼þÒÔ¼°Button¿Ø¼þ,ÐγÉÏÂͼµÄÍâ¹Û.
2.ÔÚ×öºÃÒ³ÃæºóË«»÷Button¿Ø¼þ(¼´"="),дÈëÈçÏ´úÂë:
using System;
using System.Collections.Generic;
using System.Linq;
using System ......
¶¯Ì¬Ò³ÃæÉú³É¾²Ì¬Ò³Ãæ˵ÆðÀ´Æäʵ²»ÄÑ£¬Ö÷ÒªÊÇ˼ÏëµÄÎÊÌ⣬ÏñÄÇЩÐÂÎŲ»Ì«³£¸Ä¶¯µÄ£¬ÎÒÃÇ¿ÉÒÔ½«ËûÉú³É¾²Ì¬µÄ£¬À´Ìá¸ßÍøÕ¾µÄ·ÃÎÊËٶȣ¬ÒÔϾÍÊÇÎҵķ½·¨£¬ºÜ¼òµ¥
ÎÒÃÇÏȽ«ÎÒÃǵĶ¯Ì¬ÍøÕ¾·Åµ½ÍøÉÏ£¬²¢ÇÒ¿ÉÒÔÕý³£·ÃÎÊ£¬È»ºó¾ÍÊÇÓõ½ÁËץȡҳÃæµÄ¼¼ÊõÁË
/// <summary>
/// »ñµÃÍøÒ³ÄÚÈÝ
& ......
»ñÈ¡ÍøÕ¾¸ùĿ¼µÄ·½·¨Óм¸ÖÖÈ磺
Server.MapPath(Request.ServerVariables["PATH_INFO"])
Server.MapPath("/")
Server.MapPath("")
Server.MapPath(".")
Server.MapPath("../")
Server.MapPath("..")
&nb ......
·µ»Ø°´Å¥µÄʵÏÖ·½·¨£¨asp.net ÖУ©
Òý×Ô:http://blog.sina.com.cn/s/blog_49df2d0b0100aqoy.html
·µ»ØÉÏÒ»Ò³µÄÕâ¸ö¶«¶«ÔÚÎÒÃÇ×öÏîÄ¿µÄʱºòÒ»°ãÊÇÓÃÓÚÌîдÍê±íµ¥ºóÈ·ÈϵÄʱºò£¬ÓжÔÔÀ´ÊäÈëµÄÊý¾Ý½øÐÐÐÞ¸ÄʱÓõģ¬»òÕßÊÇÒòΪÍøվΪÁË·½±ãä¯ÀÀÕ߶øÓÐÐÄÌí¼Ó µÄÒ»¸ö¶«¶«£¬Ò»°ãÕâÖÖ¹¦ÄܵÄʵÏÖÔÚASP.netÖж¼ÊÇÓÃÒ»¸öbuttonµÄ¿ ......