asp.net利用RAR实现文件压缩解压缩(转)
如果服务器上安装了RAR程序,那么asp.net可以调用RAR实现文件压缩与解压缩。
不过要注意的是,由于Web程序不能直接调用客户端的程序(除非用ActiveX,ActiveX几乎被废弃),所以如果要想实现让用户把本地文件用网页解压缩只有把文件上传到服务器上再调用服务器上的RAR压缩,同理要解压缩本地的RAR文件可以把文件上传到服务器解压再拿回来。
本文讲怎么在服务器端的目录解压缩文件!
效果图:
前台代码:
<!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.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());
}
}
}
服务器端目录:
客户端解压缩的变通方法:
转载于:https://www.cnblogs.com/gjahead/archive/2007/06/18/788120.html
asp.net利用RAR实现文件压缩解压缩(转)相关推荐
- asp.net利用RAR实现文件压缩解压缩【月儿原创】
asp.net利用RAR实现文件压缩解压缩 作者:清清月儿 主页:http://blog.csdn.net/21aspnet/ 时间:2007.6.13 如果服务器上安装了RAR程 ...
- asp.net html代码亚索,asp.net利用RAR实现文件压缩解压缩
以下为引用的内容: using System; using System.Data; using System.Configuration; using System.Web; using Syste ...
- 文件压缩解压缩,文件查找
文件压缩解压缩 常见压缩档 > *.zip | zip 程序压缩打包的档案: (很常见,但是因为不包含文档名编码信息,跨平台可能会乱码) > *.rar | rar 程序压缩打包的档案:( ...
- 最优秀好用的免费文件压缩/解压缩工具软件 —— Bandizip
最优秀好用的免费文件压缩/解压缩工具软件 -- Bandizip,可以替代WinRAR与7-Zip,我用的目前是好压唉,就是2345的好压~其实没有发现哪里不好,用了下 Bandizip,还是 Ban ...
- linux+shell+解压命令,Shell命令 文件压缩解压缩之gzip、zip详解
本篇文章的主要内容讲述的是shell命令中之文件压缩解压缩之gzip.zip,具有一定参考价值,感兴趣的朋友可以了解一下,希望对你有所帮助. 1.gzip:gzip压缩工具 gzip命令的功能说明: ...
- 服务器里解压缩gz文件夹,Shell命令文件压缩解压缩之gzip、zip的案例分析
Shell命令文件压缩解压缩之gzip.zip的案例分析 发布时间:2020-11-13 10:32:36 来源:亿速云 阅读:114 作者:小新 小编给大家分享一下Shell命令文件压缩解压缩之gz ...
- 【转】C#执行rar,zip文件压缩的几种方法及我遇到的坑总结
工作项目中需要用到zip压缩解压缩文件,一开始看上了Ionic.Zip.dll这个类库,操作方便,写法简单 对应有个ziphelper类 using Ionic.Zip;public static c ...
- 基于Huffman算法实现文件压缩解压缩(C语言)
一.实现步骤 统计源文件中字符种类和频率 建立Huffman编码树 生成Huffman编码表 压缩文件时,字符匹配编码,将编码写入压缩后文件 解压缩文件时,读取编码,匹配编码表中的字符,写入解压缩后的 ...
- linux命令—文件压缩解压缩
!/bin/bash http://www.runoob.com/linux/linux-command-manual.html # zip命令用于压缩文件 # 参数: # -A 调整可执行的自动解压 ...
最新文章
- python 运行pyc_python项目运行后产生__pycache__包含pyc格式文件
- log4j 配置文件_Log4j系列教材 (三)- log4j.xml
- Java线程类的继承结构
- Oracle索引状态查询与索引重建
- nodejs json转对象_nodejs读取xlsx格式文件
- WPF-使用代码创建Grid行与列,并将控件添加到Grid中的指定行指定列
- RS232和RS485标准在DB9公/母头上的接线定义
- 宇电智能调节仪AIBUS 及MODBUS 通讯协议说明V8.0
- 讲讲MS08067红队培训班中的“毕业实战对抗”环节 + 视频
- 【如何让代码变“高级”(二)】-这样操作值得一波666(Java Stream)(这么有趣)
- vue2+vant适配750设计稿
- seo入门最重要的是什么?
- input输入密码的时候调用纯数字键盘和加密,js弹出键盘
- 报表类-金蝶K3一次查询所有供应商采购价格
- 了解利用API接口通过网格策略的增长模式
- 可扩展java游戏框架实践之java飞机大战
- 手机换号各种绑定账号换解绑记录
- IDL实现MODIS Grid(正弦投影)产品的重投影及拼接处理
- vs 2022 下载了.net7.0预览版 还是提示当前.net sdk不支持将.net7.0设置为目标
- Elasticsearch7.x配置xpack实战
热门文章
- matlab guide 打开图像并将图像显示到界面
- (模拟+floyd)Saving James Bond
- 剩余 大小 查看内存_JVM的内存分配策略以及进入分代的条件
- springmvc工作流程_SpringMVC工作原理
- web系统软件测试功能点,小程序、app、web测试的区别
- java 原子类能做什么_死磕 java原子类之终结篇(面试题)
- C++ 文本文件的读取和写入
- oracle10g配置失败6,Oracle10g DataGuard中ORA-16026错误解决-入门基础-Oracle频道-中国IT实验室...
- php自动抓取文章图片,从文章中提取图片,把图片保存到本地,自动提取缩略图...
- GOF设计模式之桥接模式