RAR 프로그램이 서버에 설치되어 있으면 asp.net은 RAR을 호출하여 파일을 압축하고 압축을 풀 수 있습니다.
그러나 웹 프로그램은 클라이언트 프로그램을 직접 호출할 수 없기 때문에(ActiveX를 사용하지 않으면 ActiveX는 거의 포기됨) 사용자가 웹 페이지를 사용하여 로컬 파일의 압축을 풀 수 있도록 하려면 파일을 클라이언트 프로그램에 업로드만 하면 됩니다. 같은 방법으로 로컬 RAR 파일의 압축을 풀려면 파일을 서버에 업로드하여 압축을 푼 다음 다시 가져올 수 있습니다.
이 문서에서는 서버 측 디렉터리에 있는 파일의 압축을 푸는 방법을 설명합니다!
프런트엔드 코드:
<%...@ 페이지 언어="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 runat="서버">
<title>서버측 압축 해제 Qingqing Yue'er http://blog.csdn.net/21aspnet/</title >
</head>
<본문>
<form id="form1" runat="서버">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="압축" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Unzip" /></div>
</form>
</body>
</html>
백엔드 코드:
시스템 사용;
System.Data 사용;
System.Configuration 사용;
System.Web 사용;
System.Web.Security 사용;
System.Web.UI 사용;
System.Web.UI.WebControls 사용;
System.Web.UI.WebControls.WebParts 사용;
System.Web.UI.HtmlControls 사용;
System.IO 사용;
System.Runtime.InteropServices 사용;
Microsoft.Win32 사용;
System.Diagnostics 사용;
공개 부분 클래스 _Default : System.Web.UI.Page
...{
protected void Page_Load(개체 전송자, EventArgs e)
...{
//Qingqingyueerhttp://blog.csdn.net/21aspnet/
}
protected void Button1_Click(객체 전송자, EventArgs e)
...{
//압축
문자열 the_rar;
레지스트리키 the_Reg;
개체the_Obj;
문자열 the_Info;
프로세스시작정보 the_StartInfo;
_Process를 처리합니다.
노력하다
...{
the_Reg = Registry.ClassesRoot.OpenSubKey("응용 프로그램WinRAR.exeShellOpenCommand");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " a " + " 1.rar " + " " + "C:11.txt";
the_StartInfo = 새로운 ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_StartInfo.WorkingDirectory = "C:1";//시작할 프로세스의 초기 디렉터리를 가져오거나 설정합니다.
the_Process = 새로운 프로세스();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write("압축 성공");
}
잡기 (예외예외)
...{
Response.Write(ex.ToString());
}
}
protected void Button2_Click(객체 전송자, EventArgs e)
...{
//압축해제
문자열 the_rar;
레지스트리키 the_Reg;
개체the_Obj;
문자열 the_Info;
프로세스시작정보 the_StartInfo;
_Process를 처리합니다.
노력하다
...{
the_Reg = Registry.ClassesRoot.OpenSubKey("응용 프로그램WinRar.exeShellOpenCommand");
the_Obj = the_Reg.GetValue("");
the_rar = the_Obj.ToString();
the_Reg.Close();
the_rar = the_rar.Substring(1, the_rar.Length - 7);
the_Info = " X " + " 1.rar " + " " + "C:1";
the_StartInfo = 새로운 ProcessStartInfo();
the_StartInfo.FileName = the_rar;
the_StartInfo.Arguments = the_Info;
the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
the_Process = 새로운 프로세스();
the_Process.StartInfo = the_StartInfo;
the_Process.Start();
Response.Write("압축해제 성공");
}
잡기 (예외예외)
...{
Response.Write(ex.ToString());
}
}
}
http://blog.csdn.net/21aspnet/archive/2007/06/13/1649810.aspx