7-Zip for Asp.Net by shawl.qiu 2007-10-28
来源:互联网 发布:solidworks模型的数据 编辑:程序博客网 时间:2024/06/05 08:58
7-Zip for Asp.Net by shawl.qiu 2007-10-28
说明:
主要功能就是在线压缩, 解压缩...
这个程序是以 7-zip 的命令行版本为载体, 服务器不需要安装7-zip就可以使用本程序.
目前压缩格式支持: 7z, zip.
解压缩格式支持: 7z, zip, gzip, bzip2, tar, rar.
下载:
http://download.csdn.net/source/271751
结构:
G:/MYDOCU~1/INC470~1/cs/7z>tree /f
Folder PATH listing for volume Backup
Volume serial number is 0006EEEC 209C:FFAE
G:.
│ 7z.exe
│ DevNotes.txt
│ Readme.txt
│ UnZip.ascx
│ Zip.ascx
│
├─Codecs
│ 7zAES.dll
│ AES.dll
│ Branch.dll
│ BZip2.dll
│ Copy.dll
│ Deflate.dll
│ LZMA.dll
│ PPMd.dll
│ Rar29.dll
│ Swap.dll
│
├─Formats
│ 7z.dll
│ arj.dll
│ bz2.dll
│ cab.dll
│ chm.dll
│ cpio.dll
│ deb.dll
│ gz.dll
│ lzh.dll
│ rar.dll
│ rpm.dll
│ split.dll
│ tar.dll
│ z.dll
│ zip.dll
│
├─HtmlTpl
│ UnZip.ascx.htm
│ Zip.ascx.html
│
└─Test
│ UnZip_Test.aspx
│ Zip_Test.aspx
│
├─UnZipFolder
│ 7z.7z
│ 7z_Pwd-aaaaaa.7z
│
└─ZipFolder
│ UnZip.ascx.txt
│ UnZip.ascx.txt.htm
│ UnZip_Test.aspx.txt
│ UnZip_Test.aspx.txt.htm
│ Zip.ascx.txt
│ Zip.ascx.txt.htm
│ Zip_Test.aspx.txt
│ Zip_Test.aspx.txt.htm
│
└─subdir
UnZip.ascx.txt.htm
UnZip_Test.aspx.txt.htm
Zip.ascx.txt.htm
Zip_Test.aspx.txt.htm
G:/MYDOCU~1/INC470~1/cs/7z>
Folder PATH listing for volume Backup
Volume serial number is 0006EEEC 209C:FFAE
G:.
│ 7z.exe
│ DevNotes.txt
│ Readme.txt
│ UnZip.ascx
│ Zip.ascx
│
├─Codecs
│ 7zAES.dll
│ AES.dll
│ Branch.dll
│ BZip2.dll
│ Copy.dll
│ Deflate.dll
│ LZMA.dll
│ PPMd.dll
│ Rar29.dll
│ Swap.dll
│
├─Formats
│ 7z.dll
│ arj.dll
│ bz2.dll
│ cab.dll
│ chm.dll
│ cpio.dll
│ deb.dll
│ gz.dll
│ lzh.dll
│ rar.dll
│ rpm.dll
│ split.dll
│ tar.dll
│ z.dll
│ zip.dll
│
├─HtmlTpl
│ UnZip.ascx.htm
│ Zip.ascx.html
│
└─Test
│ UnZip_Test.aspx
│ Zip_Test.aspx
│
├─UnZipFolder
│ 7z.7z
│ 7z_Pwd-aaaaaa.7z
│
└─ZipFolder
│ UnZip.ascx.txt
│ UnZip.ascx.txt.htm
│ UnZip_Test.aspx.txt
│ UnZip_Test.aspx.txt.htm
│ Zip.ascx.txt
│ Zip.ascx.txt.htm
│ Zip_Test.aspx.txt
│ Zip_Test.aspx.txt.htm
│
└─subdir
UnZip.ascx.txt.htm
UnZip_Test.aspx.txt.htm
Zip.ascx.txt.htm
Zip_Test.aspx.txt.htm
G:/MYDOCU~1/INC470~1/cs/7z>
7z.exe 是命令行版本的 7-Zip
Zip.ascx 是压缩功能控件
UnZip.ascx 是解压缩功能控件
Codes 和 Formats 是压缩算法目录
test 目录提供 压缩解压演示...
注意: 里面的 .dll 不需要放到 /bin/ 文件夹
目录:
1. 压缩
1.1 Zip.ascx
1.2 Zip_test.aspx
2. 解压缩
2.1 UnZip.ascx
2.2 UnZip_test.aspx
shawl.qiu
2007-10-28
http://blog.csdn.net/btbtd
内容:
1. 压缩
1.1 Zip.ascx
<%@ Control Language="C#" AutoEventWireup="True" className="Zip" %>
<%@ import namespace="System.Diagnostics"%>
<%@ import namespace="System.IO"%>
<%@ import namespace="System.Collections"%>
<%@ import namespace="System.Text"%>
<%@ import namespace="System.Text.RegularExpressions"%>
<script runat="server">
string Path = "";
string Prog = "";
public static string InitArchivePath = "";
public static string InitSavePath = "";
public static string InitArchiveFilter = "*.*";
public static string InitPathOption = "-r";
public static string InitArchiveFormat = "zip";
public static string InitArchiveOption = "0";
SortedList SlZip = new SortedList();
SortedList Sl7z = new SortedList();
void Page_Load(Object o, EventArgs e)
{
Path = Server.MapPath(this.TemplateSourceDirectory+"/");
Prog = Path+"7z.exe";
InfoLabel.Text = "";
SlZip.Add("1. 存档", "0");
SlZip.Add("2. 默认", "5");
SlZip.Add("3. 高压缩", "9");
Sl7z.Add("1. 存档", "0");
Sl7z.Add("2. 快速压缩", "1");
Sl7z.Add("3. 默认", "5");
Sl7z.Add("4. 高压缩", "7");
Sl7z.Add("5. 超级压缩", "9");
if(!IsPostBack)
{
ArchivePath.Text = InitArchivePath;
ArchiveFilter.Text = InitArchiveFilter;
SavePath.Text = InitSavePath;
PathOption.SelectedValue = InitPathOption;
ArchiveFormat.SelectedValue = InitArchiveFormat;
InitFormat(ArchiveFormat.SelectedValue);
ArchiveOption.SelectedValue = InitArchiveOption;
}
} // end Page_Load
string GetList(string sArchivePath)
{
ArchiveFilter.Text = Regex.Replace(@ArchiveFilter.Text, @"/s+", "");
if(ArchiveFilter.Text=="") return "/""+sArchivePath+"/"";
string[] Ar = ArchiveFilter.Text.Split(',');
int Len =Ar.Length;
for(int i=0; i<Len; i++)
{
Ar[i] = "/""+sArchivePath+Ar[i]+"/"";
}
return " "+String.Join(" ", Ar);
}
void SubmitFunc(Object o, EventArgs e)
{
if(!ArchivePath.Text.EndsWith("/")) ArchivePath.Text+= "/";
string sArchivePath = Server.MapPath(ArchivePath.Text);
string sSavePath = Server.MapPath(SavePath.Text);
// Response.Write("<br/>sArchivePath: "+sArchivePath);
// Response.Write("<br/>sSavePath: "+sSavePath);
if(!Directory.Exists(sArchivePath))
{
Message(InfoLabel, "指定的压缩路径不存在!("+ArchivePath.Text+")");
return;
}
if(File.Exists(sSavePath))
{
Message(InfoLabel, "已存在压缩档: "+SavePath.Text);
return;
}
sArchivePath = GetList(sArchivePath);
string sArg =
" a /""+@sSavePath+"/" "+@sArchivePath+" "
+PathOption.SelectedValue+" -mx"+ArchiveOption.SelectedValue;
// Response.Write("<p/>sArg: "+sArg);
if(ArchivePwd.Text!="")
{
if(ArchivePwd.Text!=ConfirmArchivePwd.Text)
{
Message(InfoLabel, "压缩密码和确认密码不同! ");
return;
}
else
{
sArg += " -p"+ArchivePwd.Text;
}
} // end if(ArchivePwd.Text!="")
string sOutput = "";
Process MyPrc = new Process();
MyPrc.StartInfo.FileName = Prog;
MyPrc.StartInfo.Arguments= sArg;
MyPrc.StartInfo.UseShellExecute = false;
MyPrc.StartInfo.RedirectStandardOutput = true;
MyPrc.Start();
sOutput = MyPrc.StandardOutput.ReadToEnd();
Message(InfoLabel, "操作完毕");
Message(InfoLabel, "详细信息: <pre>"+sOutput+"</pre>");
// Process Process1 = new Process();
//
// Process1.EnableRaisingEvents = true;
//
// Process1.StartInfo.FileName = Prog;
// Process1.StartInfo.Arguments= sArg;
//
// Process1.Start();
// Process1.Exited += new EventHandler(ExitedEvent);
// Process1.WaitForExit(int.Parse(MonitorMs.SelectedValue));
} // end void SubmitFunc(Object o, EventArgs e)
void ArchiveFormatIndexChange(Object o, EventArgs e)
{
InitFormat(ArchiveFormat.SelectedValue);
}
void InitFormat(string sFormat)
{
switch(sFormat)
{
case "7z":
BindDropDownList(Sl7z, ArchiveOption);
break;
default:
BindDropDownList(SlZip, ArchiveOption);
break;
} // end switch(sFormat)
} // end void InitFormat(string sFormat)
static void BindDropDownList(SortedList Ht, DropDownList Ddl)
{
Ddl.DataSource = Ht;
Ddl.DataTextField = "Key";
Ddl.DataValueField = "Value";
Ddl.DataBind();
}
public void ExitedEvent(Object o, EventArgs e)
{
InfoLabel.Text = "";
Message(InfoLabel, "操作完毕!");
}
public static void Message(Label InfoLabel, string msg)
{
InfoLabel.Text +="<div style=/"display:table;width:100%;background-color:yellow!important;";
InfoLabel.Text +="color:black!important;text-align:center!important;margin:10px 0px;/">";
InfoLabel.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLbl, string bgcolor, string fgcolor)
{
InfoLbl.Text +="<div style=/"display:table;width:100%;background-color:"+bgcolor+"!important;";
InfoLbl.Text +="color:"+fgcolor+"!important;text-align:center!important;margin:10px 0px;/">";
InfoLbl.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLabel)
{
Message(msg, InfoLabel, "yellow", "black");
}
public static void Message(string msg, Label InfoLabel, string bgcolor)
{
Message(msg, InfoLabel, bgcolor, "black");
}
public static void Message(Label InfoLabel, string msg, string charSet)
{
InfoLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset="+
charSet+"/" />";
Message(InfoLabel, msg);
}
</script>
<style>
.SolidAll
{
/*
background-color:#FFFFFF !important;
*//*表格背景色绝对白色*/
border-collapse: collapse; /*清除 IE 的默认边框*/
border: 1px solid #999999;
}
.SolidAll tr td
{
padding:2px!important;
}
.SolidAll td, .SolidAll th
{
border-top: 1px solid #999999; /* 设置 1px 比设置为 thin 通用 */
border-right: 1px solid #999999;
border-collapse: collapse; /*清除 IE 默认边框*/
padding:2px;
}
</style>
<asp:Label ID="InfoLabel" runat="server" />
<table width="550" border="0" align="center" cellpadding="0" cellspacing="0" class="SolidAll">
<tr>
<td colspan="2" align="center"><strong>压缩文件</strong></td>
</tr>
<tr>
<td width="99" align="right">压缩路径:</td>
<td><asp:TextBox ID="ArchivePath" runat="server" Columns="40" />
(/x/)
</td>
</tr>
<tr>
<td width="99" align="right">筛选文件:</td>
<td><asp:TextBox ID="ArchiveFilter" runat="server" Columns="40" />
(*.*[,*.*])
</td>
</tr>
<tr>
<td width="99" align="right">保存路径:</td>
<td><asp:TextBox ID="SavePath" runat="server" Columns="40" />
(/x/x.x)
</td>
</tr>
<tr>
<td width="99" align="right">目录选项:</td>
<td>
<asp:DropDownList ID="PathOption" runat="server">
<asp:ListItem Value="-r">所有目录</asp:ListItem>
<asp:ListItem Value="-r-">只有当前目录</asp:ListItem>
<asp:ListItem Value="-r0">所有目录中的筛选项</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td width="99" align="right">压缩格式:</td>
<td>
<asp:DropDownList ID="ArchiveFormat" runat="server"
OnSelectedIndexChanged="ArchiveFormatIndexChange"
AutoPostBack="true"
>
<asp:ListItem Value="zip">ZIP</asp:ListItem>
<asp:ListItem Value="7z">7z</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">压缩选项:</td>
<td>
<asp:DropDownList ID="ArchiveOption" runat="server" >
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">密码:</td>
<td>
<asp:TextBox ID="ArchivePwd" runat="server"
TextMode="Password"
/>(不加密码保留为空!)
</td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td>
<asp:TextBox ID="ConfirmArchivePwd" runat="server"
TextMode="Password"
/>
</td>
</tr>
<tr>
<td align="right"> </td>
<td><input name="submit" type="submit"
onclick="return confirm('现在提交更改吗?')"
value="提交" runat="server"
onserverclick="SubmitFunc"
id="SubmitIpt">
<input name="reset" type="reset"
onclick="return confirm('现在重置吗?')"
value="重置" runat="server">
<a href="<% Response.Write(Request.Url); %>"> 返回 </a>
</td>
</tr>
</table>
<div style="text-align:center; margin:15px 0px;">
<div><b style="color:black">支持格式:</b> 7z, zip.</div>
<div style="margin:10px 0px;">
<b style="color:red;">注意:</b> 不要使用物理路径, 请使用虚拟路径! 如(/path/)<br />
</div>
<div style="margin:10px 0px;">
7-Zip for Asp.Net by <a href="http://blog.csdn.net/btbtd/" target="_blank">shawl.qiu</a>
</div>
</div>
<%@ import namespace="System.Diagnostics"%>
<%@ import namespace="System.IO"%>
<%@ import namespace="System.Collections"%>
<%@ import namespace="System.Text"%>
<%@ import namespace="System.Text.RegularExpressions"%>
<script runat="server">
string Path = "";
string Prog = "";
public static string InitArchivePath = "";
public static string InitSavePath = "";
public static string InitArchiveFilter = "*.*";
public static string InitPathOption = "-r";
public static string InitArchiveFormat = "zip";
public static string InitArchiveOption = "0";
SortedList SlZip = new SortedList();
SortedList Sl7z = new SortedList();
void Page_Load(Object o, EventArgs e)
{
Path = Server.MapPath(this.TemplateSourceDirectory+"/");
Prog = Path+"7z.exe";
InfoLabel.Text = "";
SlZip.Add("1. 存档", "0");
SlZip.Add("2. 默认", "5");
SlZip.Add("3. 高压缩", "9");
Sl7z.Add("1. 存档", "0");
Sl7z.Add("2. 快速压缩", "1");
Sl7z.Add("3. 默认", "5");
Sl7z.Add("4. 高压缩", "7");
Sl7z.Add("5. 超级压缩", "9");
if(!IsPostBack)
{
ArchivePath.Text = InitArchivePath;
ArchiveFilter.Text = InitArchiveFilter;
SavePath.Text = InitSavePath;
PathOption.SelectedValue = InitPathOption;
ArchiveFormat.SelectedValue = InitArchiveFormat;
InitFormat(ArchiveFormat.SelectedValue);
ArchiveOption.SelectedValue = InitArchiveOption;
}
} // end Page_Load
string GetList(string sArchivePath)
{
ArchiveFilter.Text = Regex.Replace(@ArchiveFilter.Text, @"/s+", "");
if(ArchiveFilter.Text=="") return "/""+sArchivePath+"/"";
string[] Ar = ArchiveFilter.Text.Split(',');
int Len =Ar.Length;
for(int i=0; i<Len; i++)
{
Ar[i] = "/""+sArchivePath+Ar[i]+"/"";
}
return " "+String.Join(" ", Ar);
}
void SubmitFunc(Object o, EventArgs e)
{
if(!ArchivePath.Text.EndsWith("/")) ArchivePath.Text+= "/";
string sArchivePath = Server.MapPath(ArchivePath.Text);
string sSavePath = Server.MapPath(SavePath.Text);
// Response.Write("<br/>sArchivePath: "+sArchivePath);
// Response.Write("<br/>sSavePath: "+sSavePath);
if(!Directory.Exists(sArchivePath))
{
Message(InfoLabel, "指定的压缩路径不存在!("+ArchivePath.Text+")");
return;
}
if(File.Exists(sSavePath))
{
Message(InfoLabel, "已存在压缩档: "+SavePath.Text);
return;
}
sArchivePath = GetList(sArchivePath);
string sArg =
" a /""+@sSavePath+"/" "+@sArchivePath+" "
+PathOption.SelectedValue+" -mx"+ArchiveOption.SelectedValue;
// Response.Write("<p/>sArg: "+sArg);
if(ArchivePwd.Text!="")
{
if(ArchivePwd.Text!=ConfirmArchivePwd.Text)
{
Message(InfoLabel, "压缩密码和确认密码不同! ");
return;
}
else
{
sArg += " -p"+ArchivePwd.Text;
}
} // end if(ArchivePwd.Text!="")
string sOutput = "";
Process MyPrc = new Process();
MyPrc.StartInfo.FileName = Prog;
MyPrc.StartInfo.Arguments= sArg;
MyPrc.StartInfo.UseShellExecute = false;
MyPrc.StartInfo.RedirectStandardOutput = true;
MyPrc.Start();
sOutput = MyPrc.StandardOutput.ReadToEnd();
Message(InfoLabel, "操作完毕");
Message(InfoLabel, "详细信息: <pre>"+sOutput+"</pre>");
// Process Process1 = new Process();
//
// Process1.EnableRaisingEvents = true;
//
// Process1.StartInfo.FileName = Prog;
// Process1.StartInfo.Arguments= sArg;
//
// Process1.Start();
// Process1.Exited += new EventHandler(ExitedEvent);
// Process1.WaitForExit(int.Parse(MonitorMs.SelectedValue));
} // end void SubmitFunc(Object o, EventArgs e)
void ArchiveFormatIndexChange(Object o, EventArgs e)
{
InitFormat(ArchiveFormat.SelectedValue);
}
void InitFormat(string sFormat)
{
switch(sFormat)
{
case "7z":
BindDropDownList(Sl7z, ArchiveOption);
break;
default:
BindDropDownList(SlZip, ArchiveOption);
break;
} // end switch(sFormat)
} // end void InitFormat(string sFormat)
static void BindDropDownList(SortedList Ht, DropDownList Ddl)
{
Ddl.DataSource = Ht;
Ddl.DataTextField = "Key";
Ddl.DataValueField = "Value";
Ddl.DataBind();
}
public void ExitedEvent(Object o, EventArgs e)
{
InfoLabel.Text = "";
Message(InfoLabel, "操作完毕!");
}
public static void Message(Label InfoLabel, string msg)
{
InfoLabel.Text +="<div style=/"display:table;width:100%;background-color:yellow!important;";
InfoLabel.Text +="color:black!important;text-align:center!important;margin:10px 0px;/">";
InfoLabel.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLbl, string bgcolor, string fgcolor)
{
InfoLbl.Text +="<div style=/"display:table;width:100%;background-color:"+bgcolor+"!important;";
InfoLbl.Text +="color:"+fgcolor+"!important;text-align:center!important;margin:10px 0px;/">";
InfoLbl.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLabel)
{
Message(msg, InfoLabel, "yellow", "black");
}
public static void Message(string msg, Label InfoLabel, string bgcolor)
{
Message(msg, InfoLabel, bgcolor, "black");
}
public static void Message(Label InfoLabel, string msg, string charSet)
{
InfoLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset="+
charSet+"/" />";
Message(InfoLabel, msg);
}
</script>
<style>
.SolidAll
{
/*
background-color:#FFFFFF !important;
*//*表格背景色绝对白色*/
border-collapse: collapse; /*清除 IE 的默认边框*/
border: 1px solid #999999;
}
.SolidAll tr td
{
padding:2px!important;
}
.SolidAll td, .SolidAll th
{
border-top: 1px solid #999999; /* 设置 1px 比设置为 thin 通用 */
border-right: 1px solid #999999;
border-collapse: collapse; /*清除 IE 默认边框*/
padding:2px;
}
</style>
<asp:Label ID="InfoLabel" runat="server" />
<table width="550" border="0" align="center" cellpadding="0" cellspacing="0" class="SolidAll">
<tr>
<td colspan="2" align="center"><strong>压缩文件</strong></td>
</tr>
<tr>
<td width="99" align="right">压缩路径:</td>
<td><asp:TextBox ID="ArchivePath" runat="server" Columns="40" />
(/x/)
</td>
</tr>
<tr>
<td width="99" align="right">筛选文件:</td>
<td><asp:TextBox ID="ArchiveFilter" runat="server" Columns="40" />
(*.*[,*.*])
</td>
</tr>
<tr>
<td width="99" align="right">保存路径:</td>
<td><asp:TextBox ID="SavePath" runat="server" Columns="40" />
(/x/x.x)
</td>
</tr>
<tr>
<td width="99" align="right">目录选项:</td>
<td>
<asp:DropDownList ID="PathOption" runat="server">
<asp:ListItem Value="-r">所有目录</asp:ListItem>
<asp:ListItem Value="-r-">只有当前目录</asp:ListItem>
<asp:ListItem Value="-r0">所有目录中的筛选项</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td width="99" align="right">压缩格式:</td>
<td>
<asp:DropDownList ID="ArchiveFormat" runat="server"
OnSelectedIndexChanged="ArchiveFormatIndexChange"
AutoPostBack="true"
>
<asp:ListItem Value="zip">ZIP</asp:ListItem>
<asp:ListItem Value="7z">7z</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">压缩选项:</td>
<td>
<asp:DropDownList ID="ArchiveOption" runat="server" >
</asp:DropDownList>
</td>
</tr>
<tr>
<td align="right">密码:</td>
<td>
<asp:TextBox ID="ArchivePwd" runat="server"
TextMode="Password"
/>(不加密码保留为空!)
</td>
</tr>
<tr>
<td align="right">确认密码:</td>
<td>
<asp:TextBox ID="ConfirmArchivePwd" runat="server"
TextMode="Password"
/>
</td>
</tr>
<tr>
<td align="right"> </td>
<td><input name="submit" type="submit"
onclick="return confirm('现在提交更改吗?')"
value="提交" runat="server"
onserverclick="SubmitFunc"
id="SubmitIpt">
<input name="reset" type="reset"
onclick="return confirm('现在重置吗?')"
value="重置" runat="server">
<a href="<% Response.Write(Request.Url); %>"> 返回 </a>
</td>
</tr>
</table>
<div style="text-align:center; margin:15px 0px;">
<div><b style="color:black">支持格式:</b> 7z, zip.</div>
<div style="margin:10px 0px;">
<b style="color:red;">注意:</b> 不要使用物理路径, 请使用虚拟路径! 如(/path/)<br />
</div>
<div style="margin:10px 0px;">
7-Zip for Asp.Net by <a href="http://blog.csdn.net/btbtd/" target="_blank">shawl.qiu</a>
</div>
</div>
1.2 Zip_test.aspx
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ import namespace="System.Web.UI.WebControls" %>
<%@ Reference Control="../Zip.ascx" %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
// Zip.InitArchivePath = "";
// Zip.InitSavePath = "";
Zip.InitArchivePath = RelativePath("../Test/ZipFolder/"); //"/cs/7z/Test/ZipFolder/";
Zip.InitArchiveFilter = "*.htm,*.txt";
Zip.InitSavePath = RelativePath("../Test/ZipFolder/7z.7z"); //"/cs/7z/Test/ZipFolder/7z.7z";
Zip.InitPathOption = "-r";
Zip.InitArchiveFormat = "7z";
Zip.InitArchiveOption = "0";
Control TempControl = LoadControl("../Zip.ascx");
MainPh.Controls.Add(TempControl);
TempControl = null;
} // end Page_Load
public static string RelativePath(string sRelPath)
{ // shawl.qiu code, return string
string sSiteRoot = System.Web.HttpContext.Current.Server.MapPath("/");
string sPhsPath = System.Web.HttpContext.Current.Server.MapPath(sRelPath);
int sSiteRootLen = sSiteRoot.Length;
int sPhsPathLen = sPhsPath.Length;
if(sSiteRootLen>=sPhsPathLen) return "/";
return sPhsPath.Substring(sSiteRootLen-1).Replace("//", "/");
} // end string RelativePath(string sRelPath)
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>压缩文档 <- 7-Zip for Asp.Net by shawl.qiu</title>
</head>
<body>
<form runat="server">
<asp:PlaceHolder ID="MainPh" runat="server"
/>
</form>
<script type="text/javascript">
/*<![CDATA[*/
/*]]*/
</script>
</body>
</html>
<%@ import namespace="System.Web.UI.WebControls" %>
<%@ Reference Control="../Zip.ascx" %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
// Zip.InitArchivePath = "";
// Zip.InitSavePath = "";
Zip.InitArchivePath = RelativePath("../Test/ZipFolder/"); //"/cs/7z/Test/ZipFolder/";
Zip.InitArchiveFilter = "*.htm,*.txt";
Zip.InitSavePath = RelativePath("../Test/ZipFolder/7z.7z"); //"/cs/7z/Test/ZipFolder/7z.7z";
Zip.InitPathOption = "-r";
Zip.InitArchiveFormat = "7z";
Zip.InitArchiveOption = "0";
Control TempControl = LoadControl("../Zip.ascx");
MainPh.Controls.Add(TempControl);
TempControl = null;
} // end Page_Load
public static string RelativePath(string sRelPath)
{ // shawl.qiu code, return string
string sSiteRoot = System.Web.HttpContext.Current.Server.MapPath("/");
string sPhsPath = System.Web.HttpContext.Current.Server.MapPath(sRelPath);
int sSiteRootLen = sSiteRoot.Length;
int sPhsPathLen = sPhsPath.Length;
if(sSiteRootLen>=sPhsPathLen) return "/";
return sPhsPath.Substring(sSiteRootLen-1).Replace("//", "/");
} // end string RelativePath(string sRelPath)
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>压缩文档 <- 7-Zip for Asp.Net by shawl.qiu</title>
</head>
<body>
<form runat="server">
<asp:PlaceHolder ID="MainPh" runat="server"
/>
</form>
<script type="text/javascript">
/*<![CDATA[*/
/*]]*/
</script>
</body>
</html>
2. 解压缩
2.1 UnZip.ascx
<%@ Control Language="C#" AutoEventWireup="True" className="UnZip" %>
<%@ import namespace="System.Diagnostics"%>
<%@ import namespace="System.IO"%>
<script runat="server">
string Path = "";
string Prog = "";
public static string InitArchivePath = "";
public static string InitUnZipPath = "";
public static string InitOverwriteMode = "-aoa";
public static string InitPathOption = "-r";
void Page_Load(Object o, EventArgs e)
{
Path = Server.MapPath(this.TemplateSourceDirectory+"/");
Prog = Path+"7z.exe";
InfoLabel.Text = "";
if(!IsPostBack)
{
ArchivePath.Text = InitArchivePath;
UnZipPath.Text = InitUnZipPath;
OverwriteMode.SelectedValue = InitOverwriteMode;
PathOption.SelectedValue = InitPathOption;
}
} // end Page_Load
void SubmitFunc(Object o, EventArgs e)
{
string sArchivePath = Server.MapPath(ArchivePath.Text);
string sUnZipPath = Server.MapPath(UnZipPath.Text);
string sArg =
" e /""+@sArchivePath+"/" -o/""+@sUnZipPath+"/" *.* "+PathOption.SelectedValue
+" "+@OverwriteMode.SelectedValue;
if(!File.Exists(sArchivePath))
{
Message(InfoLabel, "找不到压缩文件("+ArchivePath.Text+")!");
return;
}
if(ArchivePwd.Text!="")
{
sArg += "-p"+ArchivePwd.Text;
}
string sOutput = "";
Process MyPrc = new Process();
MyPrc.StartInfo.FileName = Prog;
MyPrc.StartInfo.Arguments= sArg;
MyPrc.StartInfo.UseShellExecute = false;
MyPrc.StartInfo.RedirectStandardOutput = true;
MyPrc.Start();
sOutput = MyPrc.StandardOutput.ReadToEnd();
Message(InfoLabel, "操作完毕");
Message(InfoLabel, "详细信息: <pre>"+sOutput+"</pre>");
} // end void SubmitFunc(Object o, EventArgs e)
public void ExitedEvent(Object o, EventArgs e)
{
Process p = (Process)o;
Response.Write("<br/>Prc.ExitCode: "+p.ExitCode);
InfoLabel.Text = "";
Message(InfoLabel, "操作完毕!");
}
public static void Message(Label InfoLabel, string msg)
{
InfoLabel.Text +="<div style=/"display:table;width:100%;background-color:yellow!important;";
InfoLabel.Text +="color:black!important;text-align:center!important;margin:10px 0px;/">";
InfoLabel.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLbl, string bgcolor, string fgcolor)
{
InfoLbl.Text +="<div style=/"display:table;width:100%;background-color:"+bgcolor+"!important;";
InfoLbl.Text +="color:"+fgcolor+"!important;text-align:center!important;margin:10px 0px;/">";
InfoLbl.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLabel)
{
Message(msg, InfoLabel, "yellow", "black");
}
public static void Message(string msg, Label InfoLabel, string bgcolor)
{
Message(msg, InfoLabel, bgcolor, "black");
}
public static void Message(Label InfoLabel, string msg, string charSet)
{
InfoLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset="+
charSet+"/" />";
Message(InfoLabel, msg);
}
</script>
<style>
.SolidAll
{
/*
background-color:#FFFFFF !important;
*//*表格背景色绝对白色*/
border-collapse: collapse; /*清除 IE 的默认边框*/
border: 1px solid #999999;
}
.SolidAll tr td
{
padding:2px!important;
}
.SolidAll td, .SolidAll th
{
border-top: 1px solid #999999; /* 设置 1px 比设置为 thin 通用 */
border-right: 1px solid #999999;
border-collapse: collapse; /*清除 IE 默认边框*/
padding:2px;
}
</style>
<asp:Label ID="InfoLabel" runat="server" />
<table width="500" border="0" cellspacing="0" cellpadding="0" class="SolidAll" align="center">
<tr>
<td colspan="2" align="center" valign="top"><strong>解压文件</strong></td>
</tr>
<tr>
<td width="99" align="right" valign="top">压缩文件:<br/></td>
<td align="left" valign="top"><asp:TextBox ID="ArchivePath" runat="server" Columns="50"></asp:TextBox><br /> </td>
</tr>
<tr>
<td width="99" align="right" valign="top">解压到:</td>
<td align="left" valign="top"><asp:TextBox ID="UnZipPath" runat="server" Columns="50"></asp:TextBox>
<br /></td>
</tr>
<tr>
<td align="right" valign="top">覆盖模式:</td>
<td align="left" valign="top">
<asp:DropDownList ID="OverwriteMode" runat="server">
<asp:ListItem Value="-aoa" Selected="true">覆盖所有</asp:ListItem>
<asp:ListItem Value="-aos">跳过已有文件</asp:ListItem>
<asp:ListItem Value="-aou">自动重命名压缩包内文件</asp:ListItem>
<asp:ListItem Value="-aot">自动重命名已有文件</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td width="99" align="right">目录选项:</td>
<td>
<asp:DropDownList ID="PathOption" runat="server">
<asp:ListItem Value="-r">所有目录</asp:ListItem>
<asp:ListItem Value="-r-">只有当前目录</asp:ListItem>
<asp:ListItem Value="-r0">所有目录中的筛选项</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right">密码:</td>
<td><asp:TextBox ID="ArchivePwd" runat="server"
TextMode="Password"
/>
(不加密码保留为空!) </td>
</tr>
<tr>
<td width="99" align="right" valign="top"> </td>
<td align="left" valign="top">
<input name="submit" type="submit"
onclick="return confirm('现在提交更改吗?')"
value="提交" runat="server"
onserverclick="SubmitFunc"
id="SubmitIpt"
/>
<input name="reset" type="reset"
onclick="return confirm('现在重置吗?')"
value="重置" runat="server"
/>
<a href="<% Response.Write(Request.Url); %>">
返回 </a> </td>
</tr>
</table>
<div style="text-align:center; margin:15px 0px;">
<div><b style="color:black">支持格式:</b> 7z, zip, gzip, bzip2, tar, rar.</div>
<div style="margin:10px 0px;">
<b style="color:red;">注意:</b> 不要使用物理路径, 请使用虚拟路径! 如(/path/)<br />
</div>
<div style="margin:10px 0px;">
7-Zip for Asp.Net by <a href="http://blog.csdn.net/btbtd/" target="_blank">shawl.qiu</a>
</div>
</div>
<%@ import namespace="System.Diagnostics"%>
<%@ import namespace="System.IO"%>
<script runat="server">
string Path = "";
string Prog = "";
public static string InitArchivePath = "";
public static string InitUnZipPath = "";
public static string InitOverwriteMode = "-aoa";
public static string InitPathOption = "-r";
void Page_Load(Object o, EventArgs e)
{
Path = Server.MapPath(this.TemplateSourceDirectory+"/");
Prog = Path+"7z.exe";
InfoLabel.Text = "";
if(!IsPostBack)
{
ArchivePath.Text = InitArchivePath;
UnZipPath.Text = InitUnZipPath;
OverwriteMode.SelectedValue = InitOverwriteMode;
PathOption.SelectedValue = InitPathOption;
}
} // end Page_Load
void SubmitFunc(Object o, EventArgs e)
{
string sArchivePath = Server.MapPath(ArchivePath.Text);
string sUnZipPath = Server.MapPath(UnZipPath.Text);
string sArg =
" e /""+@sArchivePath+"/" -o/""+@sUnZipPath+"/" *.* "+PathOption.SelectedValue
+" "+@OverwriteMode.SelectedValue;
if(!File.Exists(sArchivePath))
{
Message(InfoLabel, "找不到压缩文件("+ArchivePath.Text+")!");
return;
}
if(ArchivePwd.Text!="")
{
sArg += "-p"+ArchivePwd.Text;
}
string sOutput = "";
Process MyPrc = new Process();
MyPrc.StartInfo.FileName = Prog;
MyPrc.StartInfo.Arguments= sArg;
MyPrc.StartInfo.UseShellExecute = false;
MyPrc.StartInfo.RedirectStandardOutput = true;
MyPrc.Start();
sOutput = MyPrc.StandardOutput.ReadToEnd();
Message(InfoLabel, "操作完毕");
Message(InfoLabel, "详细信息: <pre>"+sOutput+"</pre>");
} // end void SubmitFunc(Object o, EventArgs e)
public void ExitedEvent(Object o, EventArgs e)
{
Process p = (Process)o;
Response.Write("<br/>Prc.ExitCode: "+p.ExitCode);
InfoLabel.Text = "";
Message(InfoLabel, "操作完毕!");
}
public static void Message(Label InfoLabel, string msg)
{
InfoLabel.Text +="<div style=/"display:table;width:100%;background-color:yellow!important;";
InfoLabel.Text +="color:black!important;text-align:center!important;margin:10px 0px;/">";
InfoLabel.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLbl, string bgcolor, string fgcolor)
{
InfoLbl.Text +="<div style=/"display:table;width:100%;background-color:"+bgcolor+"!important;";
InfoLbl.Text +="color:"+fgcolor+"!important;text-align:center!important;margin:10px 0px;/">";
InfoLbl.Text += msg+"</div>";
}
public static void Message(string msg, Label InfoLabel)
{
Message(msg, InfoLabel, "yellow", "black");
}
public static void Message(string msg, Label InfoLabel, string bgcolor)
{
Message(msg, InfoLabel, bgcolor, "black");
}
public static void Message(Label InfoLabel, string msg, string charSet)
{
InfoLabel.Text+="<meta http-equiv=/"Content-Type/" content=/"text/html; charset="+
charSet+"/" />";
Message(InfoLabel, msg);
}
</script>
<style>
.SolidAll
{
/*
background-color:#FFFFFF !important;
*//*表格背景色绝对白色*/
border-collapse: collapse; /*清除 IE 的默认边框*/
border: 1px solid #999999;
}
.SolidAll tr td
{
padding:2px!important;
}
.SolidAll td, .SolidAll th
{
border-top: 1px solid #999999; /* 设置 1px 比设置为 thin 通用 */
border-right: 1px solid #999999;
border-collapse: collapse; /*清除 IE 默认边框*/
padding:2px;
}
</style>
<asp:Label ID="InfoLabel" runat="server" />
<table width="500" border="0" cellspacing="0" cellpadding="0" class="SolidAll" align="center">
<tr>
<td colspan="2" align="center" valign="top"><strong>解压文件</strong></td>
</tr>
<tr>
<td width="99" align="right" valign="top">压缩文件:<br/></td>
<td align="left" valign="top"><asp:TextBox ID="ArchivePath" runat="server" Columns="50"></asp:TextBox><br /> </td>
</tr>
<tr>
<td width="99" align="right" valign="top">解压到:</td>
<td align="left" valign="top"><asp:TextBox ID="UnZipPath" runat="server" Columns="50"></asp:TextBox>
<br /></td>
</tr>
<tr>
<td align="right" valign="top">覆盖模式:</td>
<td align="left" valign="top">
<asp:DropDownList ID="OverwriteMode" runat="server">
<asp:ListItem Value="-aoa" Selected="true">覆盖所有</asp:ListItem>
<asp:ListItem Value="-aos">跳过已有文件</asp:ListItem>
<asp:ListItem Value="-aou">自动重命名压缩包内文件</asp:ListItem>
<asp:ListItem Value="-aot">自动重命名已有文件</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td width="99" align="right">目录选项:</td>
<td>
<asp:DropDownList ID="PathOption" runat="server">
<asp:ListItem Value="-r">所有目录</asp:ListItem>
<asp:ListItem Value="-r-">只有当前目录</asp:ListItem>
<asp:ListItem Value="-r0">所有目录中的筛选项</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td align="right">密码:</td>
<td><asp:TextBox ID="ArchivePwd" runat="server"
TextMode="Password"
/>
(不加密码保留为空!) </td>
</tr>
<tr>
<td width="99" align="right" valign="top"> </td>
<td align="left" valign="top">
<input name="submit" type="submit"
onclick="return confirm('现在提交更改吗?')"
value="提交" runat="server"
onserverclick="SubmitFunc"
id="SubmitIpt"
/>
<input name="reset" type="reset"
onclick="return confirm('现在重置吗?')"
value="重置" runat="server"
/>
<a href="<% Response.Write(Request.Url); %>">
返回 </a> </td>
</tr>
</table>
<div style="text-align:center; margin:15px 0px;">
<div><b style="color:black">支持格式:</b> 7z, zip, gzip, bzip2, tar, rar.</div>
<div style="margin:10px 0px;">
<b style="color:red;">注意:</b> 不要使用物理路径, 请使用虚拟路径! 如(/path/)<br />
</div>
<div style="margin:10px 0px;">
7-Zip for Asp.Net by <a href="http://blog.csdn.net/btbtd/" target="_blank">shawl.qiu</a>
</div>
</div>
2.2 UnZip_test.aspx
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ import namespace="System.Web.UI.WebControls" %>
<%@ Reference Control="../UnZip.ascx" %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
//"/cs/7z/Test/UnZipFolder/7z.7z";
UnZip.InitArchivePath = RelativePath("../Test/UnZipFolder/7z.7z");
UnZip.InitUnZipPath = RelativePath("../Test/UnZipFolder/"); //"/cs/7z/Test/UnZipFolder/";
UnZip.InitOverwriteMode = "-aoa";
UnZip.InitPathOption = "-r";
Control TempControl = LoadControl("../UnZip.ascx");
MainPh.Controls.Add(TempControl);
TempControl = null;
} // end Page_Load
public static string RelativePath(string sRelPath)
{ // shawl.qiu code, return string
string sSiteRoot = System.Web.HttpContext.Current.Server.MapPath("/");
string sPhsPath = System.Web.HttpContext.Current.Server.MapPath(sRelPath);
int sSiteRootLen = sSiteRoot.Length;
int sPhsPathLen = sPhsPath.Length;
if(sSiteRootLen>=sPhsPathLen) return "/";
return sPhsPath.Substring(sSiteRootLen-1).Replace("//", "/");
} // end string RelativePath(string sRelPath)
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>解压文档 <- 7-Zip for Asp.Net by shawl.qiu</title>
</head>
<body>
<form runat="server">
<asp:PlaceHolder ID="MainPh" runat="server"
/>
</form>
<script type="text/javascript">
/*<![CDATA[*/
/*]]*/
</script>
</body>
</html>
<%@ import namespace="System.Web.UI.WebControls" %>
<%@ Reference Control="../UnZip.ascx" %>
<script runat="server">
void Page_Load(Object s, EventArgs e)
{
//"/cs/7z/Test/UnZipFolder/7z.7z";
UnZip.InitArchivePath = RelativePath("../Test/UnZipFolder/7z.7z");
UnZip.InitUnZipPath = RelativePath("../Test/UnZipFolder/"); //"/cs/7z/Test/UnZipFolder/";
UnZip.InitOverwriteMode = "-aoa";
UnZip.InitPathOption = "-r";
Control TempControl = LoadControl("../UnZip.ascx");
MainPh.Controls.Add(TempControl);
TempControl = null;
} // end Page_Load
public static string RelativePath(string sRelPath)
{ // shawl.qiu code, return string
string sSiteRoot = System.Web.HttpContext.Current.Server.MapPath("/");
string sPhsPath = System.Web.HttpContext.Current.Server.MapPath(sRelPath);
int sSiteRootLen = sSiteRoot.Length;
int sPhsPathLen = sPhsPath.Length;
if(sSiteRootLen>=sPhsPathLen) return "/";
return sPhsPath.Substring(sSiteRootLen-1).Replace("//", "/");
} // end string RelativePath(string sRelPath)
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>解压文档 <- 7-Zip for Asp.Net by shawl.qiu</title>
</head>
<body>
<form runat="server">
<asp:PlaceHolder ID="MainPh" runat="server"
/>
</form>
<script type="text/javascript">
/*<![CDATA[*/
/*]]*/
</script>
</body>
</html>
- 7-Zip for Asp.Net by shawl.qiu 2007-10-28
- sqEditor HTML 编辑器 for .net v1.0 By shawl.qiu
- ASP 初阶笔记 By Shawl.qiu
- asp.net 中 使用 ado 的 Recordset GetString 函数 By shawl.qiu
- asp.net DataList 复选框 也玩 全选反选全不选 by shawl.qiu
- asp jscript 调用 asp vbscript class/类, by shawl.qiu
- ASP VBScript 动态包含文件, FSO 实现 By Shawl.qiu
- ASP 优化之显示数据查询内容 By shawl.qiu
- ASP + Access 初阶笔记 By Shawl.qiu
- ASP VBScript 函数 之返回多个值 By shawl.qiu
- ASP ADO getRows() 使用演示 By shawl.qiu
- ASP CDO.Message 发送邮件完整实例 By shawl.qiu
- c# .net 上传多个文件 By shawl.qiu
- c# .net 生成缩略图(按比例) By shawl.qiu
- c# .net 生成图片验证码 By shawl.qiu
- Javascript 动态添加表格行(Tr),表格单元(Td) By shawl.qiu 2007-9-7
- 关闭Modem拔号音 By Shawl.qiu
- js prototype 格式化数字 By shawl.qiu
- Word2003保存时提示语音数据无法保存怎么办?解决方法
- 开始启动csdn博客
- Tomcat JNDI配置
- One perfect book for C++
- 用C#编写ActiveX控件
- 7-Zip for Asp.Net by shawl.qiu 2007-10-28
- Find命令常见的使用方法
- c# 代码整理集1
- typedef struct与struct的区别
- 用C#编写ActiveX控件(一)
- 用C#编写ActiveX控件(二)
- QQ上线后
- 批量修改数据库中数据
- c# 代码整理集2