`
阅读更多

如果服务器上安装了RAR程序,那么asp.net可以调用RAR实现文件压缩与解压缩。

不过要注意的是,由于Web程序不能直接调用客户端的程序(除非用ActiveX,ActiveX几乎被废弃),所以如果要想实现让用户把本地文件用网页解压缩只有把文件上传到服务器上再调用服务器上的RAR压缩,同理要解压缩本地的RAR文件可以把文件上传到服务器解压再拿回来。

本文讲怎么在服务器端的目录解压缩文件!

效果图:

 前台代码:
<%...@ Page Language="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="server">
    
<title>服务器端解压缩  清清月儿 http://blog.csdn.net/21aspnet/</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="压缩" />
        
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="解压缩" /></div>
    
</form>
</body>
</html>

 

后台代码:

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;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.Diagnostics;
public partial class _Default : System.Web.UI.Page 
...{
    
protected void Page_Load(object sender, EventArgs e)
    
...{
        
//清清月儿 http://blog.csdn.net/21aspnet/
    }

    
protected void Button1_Click(object sender, EventArgs e)
    
...{
        
//压缩
        String the_rar;
        RegistryKey the_Reg;
        Object the_Obj;
        String the_Info;
        ProcessStartInfo the_StartInfo;
        Process the_Process;
        
try
        
...{
            the_Reg 
= Registry.ClassesRoot.OpenSubKey("Applications\WinRAR.exe\Shell\Open\Command");
            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:\1\1.txt";
            the_StartInfo 
= new ProcessStartInfo();
            the_StartInfo.FileName 
= the_rar;
            the_StartInfo.Arguments 
= the_Info;
            the_StartInfo.WindowStyle 
= ProcessWindowStyle.Hidden;
            the_StartInfo.WorkingDirectory 
= "C:\1";//获取或设置要启动的进程的初始目录。
            the_Process = new Process();
            the_Process.StartInfo 
= the_StartInfo;
            the_Process.Start();
            Response.Write(
"压缩成功");
        }

        
catch (Exception ex)
        
...{
            Response.Write(ex.ToString());
        }

    }

    
protected void Button2_Click(object sender, EventArgs e)
    
...{
        
//解压缩
        String the_rar;
        RegistryKey the_Reg;
        Object the_Obj;
        String the_Info;
        ProcessStartInfo the_StartInfo;
        Process the_Process;
        
try
        
...{
            the_Reg 
= Registry.ClassesRoot.OpenSubKey("Applications\WinRar.exe\Shell\Open\Command");
            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 
= new ProcessStartInfo();
            the_StartInfo.FileName 
= the_rar;
            the_StartInfo.Arguments 
= the_Info;
            the_StartInfo.WindowStyle 
= ProcessWindowStyle.Hidden;
            the_Process 
= new Process();
            the_Process.StartInfo 
= the_StartInfo;
            the_Process.Start();
            Response.Write(
"解压缩成功");
        }

        
catch (Exception ex)
        
...{
            Response.Write(ex.ToString());
        }

    }

}

 

服务器端目录:

客户端解压缩的变通方法:

分享到:
评论

相关推荐

    asp.net调用RAR实现文件压缩与解压缩图文代码

    如果服务器上安装了RAR程序,那么asp.net可以调用RAR实现文件压缩与解压缩。 不过要注意的是,由于Web程序不能直接调用客户端的程序(除非用ActiveX,ActiveX几乎被废弃),所以如果要想实现让用户把本地文件用网页...

    ASP.NET利用RAR实现文件压缩解压缩

    介绍在ASP.NET中怎么利用WinRAR实现文件压缩/解压缩

    asp.net 解压缩文件

    如果服务器上安装了RAR程序,那么asp.net可以调用RAR实现文件压缩与解压缩。

    asp.net中调用winrar实现压缩解压缩的代码

    asp.net解压缩rar文件调用示例:unrar(“e:/www.jb51.net.rar”, “e:/”); 代码如下: using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace BLL { public ...

    asp.NET中实现文件的压缩和解压(3种方式)

    本篇文章主要介绍了asp.NET中实现文件的压缩和解压,这里整理了详细的代码,有需要的小伙伴可以参考下。

    asp.net知识库

    利用反射实现ASP.NET控件和数据实体之间的双向绑定,并且在客户端自动验证输入的内容是否合法 asp.net报表解决方法 SQLDMO类的使用 SQL过程自动C#封装,支持从表到基本存储过程生成 使用SQLDMO控制 SQL Server 使用SQL...

    asp.net 2.0 动态网站开发教程(5-1)

    ASP.NET 2.0 动态网站开发教程 PDF格式 清华大学出版社 高等院校计算机教育系列教材 程不功 龙跃进 卓琳 主编 全书不到300页,共21章分为四...全部下载后放到一个文件夹中,解压缩后就可以使用了,呵呵. 祝大家好运!

    ASP.Net网络资源管理器及源代码

    3、可上传压缩文件(*.zip,*.rar),然后在用户主目录解?,也可对文件(夹)进行压缩; 4、可下载文件、对于文件夹或是多个文件则进行压缩打包成(DownLoad.zip)下载; 5、分割文件(为减轻服务器负担,设定为2~5...

    fileManage ASP.NET在线文件和目录管理程序(FSO)

     3、可上传压缩文件(*.zip,*.rar),然后利用winrar软件,在用户主目录解圧,也可对文件(夹)进行压缩;  4、可下载文件、对于文件夹或是多个文件则进行压缩打包成(DownLoad.zip)下载;  5、分割文件(为减轻...

    7-Zip for Asp.Net by shawl.qiu

    说明: 主要功能就是在线压缩, 解压缩... 这个程序是以 7-zip 的命令行版本为载体, 服务器不需要安装7-zip就可以使用本程序. &lt;br&gt;目前压缩格式支持: 7z, zip. 解压缩格式支持: 7z, zip, gzip, bzip2,...

    ASP.Net网络资源管理器 v2.0

    3、可上传压缩文件(*.zip,*.rar),然后在用户主目录解圧,也可对文件(夹)进行压缩;4、可下载文件、对于文件夹或是多个文件则进行压缩打包成(DownLoad.zip)下载;5、分割文件(为减轻服务器负担,设定为2~5个...

    FxBlog博客系统源码 v1.0 ASP.NET版.rar

     下载本程序包至本地并解压缩,将目录里的全部文件上传至根目录。  升级安装  升级前请先备份程序,覆盖bin、content、views文件夹  管理登录  打开http://您的域名/manage/login,初始账号:admin,密码:...

    ASP.NET 2.0 动态网站开发教程(5-5)

    ASP.NET 2.0 动态网站开发教程 &lt;br&gt;PDF格式 清华大学出版社 高等院校计算机教育系列教材 程不功 龙跃进 卓琳 主编 &lt;br&gt;全书不到300页,共21章分为四个部分 第一部分介绍ASP.NET 2.0的基础知识;...

    ASP.NET 2.0 动态网站开发教程(5-4)

    ASP.NET 2.0 动态网站开发教程 &lt;br&gt;PDF格式 清华大学出版社 高等院校计算机教育系列教材 程不功 龙跃进 卓琳 主编 &lt;br&gt;全书不到300页,共21章分为四个部分 第一部分介绍ASP.NET 2.0的基础知识;...

    ASP.NET 2.0 动态网站开发教程(5-2)

    ASP.NET 2.0 动态网站开发教程 &lt;br&gt;PDF格式 清华大学出版社 高等院校计算机教育系列教材 程不功 龙跃进 卓琳 主编 &lt;br&gt;全书不到300页,共21章分为四个部分 第一部分介绍ASP.NET 2.0的基础知识;...

    ASP.NET 2.0 动态网站开发教程(5-3)

    ASP.NET 2.0 动态网站开发教程 &lt;br&gt;PDF格式 清华大学出版社 高等院校计算机教育系列教材 程不功 龙跃进 卓琳 主编 &lt;br&gt;全书不到300页,共21章分为四个部分 第一部分介绍ASP.NET 2.0的基础知识;...

    AspxZip在线压缩解压ZIP文档 2.0.rar

    这就是我写这个 AspxZip 在线打包压缩/解压缩程序的原始动机。 AspxZip 的设计目的是想通过友好的Web界面方便的对存放在远程Web服务器上的文档进行压缩打包和解压缩操作,从而方便备份/还原Web服务器上的各种数据。...

Global site tag (gtag.js) - Google Analytics