using System.IO;
using System.Net;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
string serverPath = Server.MapPath("File");
DirectoryInfo dir = new DirectoryInfo(serverPath);
foreach (FileInfo fileName in dir.GetFiles())
{
DataRow dr = dt.NewRow();
dr[0] = fileName;
dt.Rows.Add(dr);
}
ListBox1.DataSource = dt;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "Name";
ListBox1.DataBind();
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt"] = ListBox1.SelectedValue.ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session["txt"] != "")
{
string path = Server.MapPath("File/") + Session["txt"].ToString();
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" +Server.HtmlDecode( fi.Name));
}
}
}
}
在线压缩
using System.Net;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
string serverPath = Server.MapPath("File");
DirectoryInfo dir = new DirectoryInfo(serverPath);
foreach (FileInfo fileName in dir.GetFiles())
{
DataRow dr = dt.NewRow();
dr[0] = fileName;
dt.Rows.Add(dr);
}
ListBox1.DataSource = dt;
ListBox1.DataTextField = "Name";
ListBox1.DataValueField = "Name";
ListBox1.DataBind();
}
}
protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
Session["txt"] = ListBox1.SelectedValue.ToString();
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (Session["txt"] != "")
{
string path = Server.MapPath("File/") + Session["txt"].ToString();
FileInfo fi = new FileInfo(path);
if (fi.Exists)
{
Response.AddHeader("Content-Disposition", "attachment;filename=" +Server.HtmlDecode( fi.Name));
}
}
}
}
在线压缩
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
try
{
compressFile.CompressFile(FileUpload1.PostedFile.FileName, TextBox1.Text);
Response.Write("<script>alert('压缩成功。')</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('"+ex.ToString()+"')</script>");
}
}
protected void btnExit_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
}
------------------------------解压
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ }
protected void Button1_Click(object sender, EventArgs e)
{
try
{
decompressFile.DecompressFile(FileUpload1.PostedFile.FileName, TextBox1.Text.Trim());
Response.Write("<script>alert('解压成功。')</script>");
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.ToString() + "')</script>");
}
}
protected void btnExit_Click(object sender, EventArgs e)
{
Response.Write("<script>window.close()</script>");
}
}