asp.net利用RAR实现文件压缩解压缩

作者:互联网

2009-07-01

ASP.NET教程

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

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

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

 前台代码:
<%...@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>



    服务器端解压缩  清清月儿 ><br></head><br><body><br>    <form id="form1" runat="server"><br>    <div><br>        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="压缩" /><br>        <asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="解压缩" /></div><br>    </form><br></body><br></html></p> <p> </p> <p>后台代码:</p> <p>using System;<br>using System.Data;<br>using System.Configuration;<br>using System.Web;<br>using System.Web.Security;<br>using System.Web.UI;<br>using System.Web.UI.WebControls;<br>using System.Web.UI.WebControls.WebParts;<br>using System.Web.UI.HtmlControls;<br>using System.IO;<br>using System.Runtime.InteropServices;<br>using Microsoft.Win32;<br>using System.Diagnostics;<br>public partial class _Default : System.Web.UI.Page <br>...{<br>    protected void Page_Load(object sender, EventArgs e)<br>    ...{<br>        //清清月儿 <br>    }<br>    protected void Button1_Click(object sender, EventArgs e)<br>    ...{<br>        //压缩<br>        String the_rar;<br>        RegistryKey the_Reg;<br>        Object the_Obj;<br>        String the_Info;<br>        ProcessStartInfo the_StartInfo;<br>        Process the_Process;<br>        try<br>        ...{<br>            the_Reg = Registry.ClassesRoot.OpenSubKey("ApplicationsWinRAR.exeShellOpenCommand");<br>            the_Obj = the_Reg.GetValue("");<br>            the_rar = the_Obj.ToString();<br>            the_Reg.Close();<br>            the_rar = the_rar.Substring(1, the_rar.Length - 7);<br>            the_Info = " a    " + " 1.rar " + "  " + "C:11.txt";<br>            the_StartInfo = new ProcessStartInfo();<br>            the_StartInfo.FileName = the_rar;<br>            the_StartInfo.Arguments = the_Info;<br>            the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br>            the_StartInfo.WorkingDirectory = "C:1";//获取或设置要启动的进程的初始目录。<br>            the_Process = new Process();<br>            the_Process.StartInfo = the_StartInfo;<br>            the_Process.Start();<br>            Response.Write("压缩成功");<br>        }<br>        catch (Exception ex)<br>        ...{<br>            Response.Write(ex.ToString());<br>        }<br>    }<br>    protected void Button2_Click(object sender, EventArgs e)<br>    ...{<br>        //解压缩<br>        String the_rar;<br>        RegistryKey the_Reg;<br>        Object the_Obj;<br>        String the_Info;<br>        ProcessStartInfo the_StartInfo;<br>        Process the_Process;<br>        try<br>        ...{<br>            the_Reg = Registry.ClassesRoot.OpenSubKey("ApplicationsWinRar.exeShellOpenCommand");<br>            the_Obj = the_Reg.GetValue("");<br>            the_rar = the_Obj.ToString();<br>            the_Reg.Close();<br>            the_rar = the_rar.Substring(1, the_rar.Length - 7);<br>            the_Info = " X " + " 1.rar " + " " + "C:1";<br>            the_StartInfo = new ProcessStartInfo();<br>            the_StartInfo.FileName = the_rar;<br>            the_StartInfo.Arguments = the_Info;<br>            the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;<br>            the_Process = new Process();<br>            the_Process.StartInfo = the_StartInfo;<br>            the_Process.Start();<br>            Response.Write("解压缩成功");<br>        }<br>        catch (Exception ex)<br>        ...{<br>            Response.Write(ex.ToString());<br>        }<br>    }<br>}<br></p></span> </div> <div class="artmoretabs flexRow"> <p>相关标签:</p> <div class="mtbs flexRow"> <span class="mtbsa flexRow check" title="ASP.NET">ASP.NET</span> </div> </div> <div class="lastanext flexRow"> <a class="lastart flexRow" href="/wz/6470.html" ><span>上一篇:</span><span>手把手教你如何扩展GridView之个性分页</span></a> <a class="nextart flexRow" href="/wz/6472.html" ><span>下一篇:</span><span>认识asp.net会话状态</span></a> </div> </div> <div class="dtl-xgtj"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>相关推荐</p></div> </div> <div class="tjlist flexRow"> <div class="tj-item "> <div class="tjitemd"> <div class="tjimd-top flexRow"> <a class="imdta flexRow" href="/wz/365631.html" > <img src="https://images.jiaoben.net/uploads/20260417/logo_69e1ebbf94fdb1.jpeg" > </a> <div class="imdt-right flexColumn"> <a class="imdtra flexRow overflowclass" href="/wz/365631.html" >MyBatis、MyBatis-Plus、JPA、MyBatisGX 写法比较:同一个需求,四种解法</a> <a class="imdtrap flexRow overflowclass" href="/wz/365631.html" > MyBatis、MyBatis-Plus、JPA、MyBatisGX 写法比较:同一个需求,四种解法 场景 1:一个"普通"的用户管理需求 产品经理说,用户模块需要支持: 新增用户 查询用户详情(带出 </a> </div> </div> <div class="tjimd-down flexRow"> <div class="imdd-tab flexRow"> <p class="imddt-time flexRow"><b></b><span>2026-04-17</span></p> </div> <a href="/wz/365631.html" class="imdd-more flexRow flexcenter" >立即查看</a> </div> </div> </div> <div class="tj-item "> <div class="tjitemd"> <div class="tjimd-top flexRow"> <a class="imdta flexRow" href="/wz/365623.html" > <img src="https://images.jiaoben.net/uploads/20260417/logo_69e1eb3a2def91.jpeg" > </a> <div class="imdt-right flexColumn"> <a class="imdtra flexRow overflowclass" href="/wz/365623.html" >【从0到1构建一个ClaudeAgent】并发-后台任务</a> <a class="imdtrap flexRow overflowclass" href="/wz/365623.html" > 有些操作很慢,Agent 不能干等着。例如**长时间编译/构建**:`make`, `mvn c </a> </div> </div> <div class="tjimd-down flexRow"> <div class="imdd-tab flexRow"> <p class="imddt-time flexRow"><b></b><span>2026-04-17</span></p> </div> <a href="/wz/365623.html" class="imdd-more flexRow flexcenter" >立即查看</a> </div> </div> </div> <div class="tj-item "> <div class="tjitemd"> <div class="tjimd-top flexRow"> <a class="imdta flexRow" href="/wz/365565.html" > <img src="https://images.jiaoben.net/uploads/20260417/logo_69e1dc6c2e9ec1.jpeg" > </a> <div class="imdt-right flexColumn"> <a class="imdtra flexRow overflowclass" href="/wz/365565.html" >java2AI系列:SpringAI 通过 Function Calling 接入外部系统</a> <a class="imdtrap flexRow overflowclass" href="/wz/365565.html" > 在做企业级的RAG时,需要投喂外部系统的数据给模型,以生成更符合需要的回答。我们都知道模型的知识是有限的,在训练完成后,它的参数就固定了。大多数的模型,目前还无法自主更新知识库,即不知道训练数据以外的 </a> </div> </div> <div class="tjimd-down flexRow"> <div class="imdd-tab flexRow"> <p class="imddt-time flexRow"><b></b><span>2026-04-17</span></p> </div> <a href="/wz/365565.html" class="imdd-more flexRow flexcenter" >立即查看</a> </div> </div> </div> <div class="tj-item "> <div class="tjitemd"> <div class="tjimd-top flexRow"> <a class="imdta flexRow" href="/wz/365521.html" > <img src="https://images.jiaoben.net/uploads/20260417/logo_69e1cf9d697db1.jpeg" > </a> <div class="imdt-right flexColumn"> <a class="imdtra flexRow overflowclass" href="/wz/365521.html" >深度剖析:Java 并发三大量难题 —— 死锁、活锁、饥饿全解</a> <a class="imdtrap flexRow overflowclass" href="/wz/365521.html" > 本文深入剖析Java并发中三大顽疾:死锁(线程永久阻塞)、活锁(线程忙等无效运行)、饥饿(低优先级线程长期得不到资源)。厘清其本质区别、触发条件、实战案例及jstack/Arthas等排查方案。 </a> </div> </div> <div class="tjimd-down flexRow"> <div class="imdd-tab flexRow"> <p class="imddt-time flexRow"><b></b><span>2026-04-17</span></p> </div> <a href="/wz/365521.html" class="imdd-more flexRow flexcenter" >立即查看</a> </div> </div> </div> </div> </div> </div> <div class="cd-right dtlcd-right"> <div class="dtl-ht"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>专题</p></div> </div> <div class="dtlht-list "> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-69351.html" >#数据可视化</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-69351.html" >数据可视化(Data Visu</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="69351" >+ 收藏</p> </div> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-69342.html" >#自然语言处理</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-69342.html" >自然语言处理(Natural</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="69342" >+ 收藏</p> </div> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-68363.html" >#Excel公式</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-68363.html" >Excel公式就是:用函数 +</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="68363" >+ 收藏</p> </div> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-68355.html" >#Excel技巧</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-68355.html" >Excel是日常生活中必不可</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="68355" >+ 收藏</p> </div> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-68081.html" >#蛋仔派对</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-68081.html" >蛋仔派对最新官方活动、关卡速</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="68081" >+ 收藏</p> </div> <div class="htl-item flexRow"> <div class="htmitem-left"> <div class="htiteml-top flexRow"> <a href="/wz/zt-68000.html" >#人工智能</a> <span></span> </div> <a class="htiteml-down flexRow" href="/wz/zt-68000.html" >人工智能(AI),简单说,就</a> </div> <p class="htmitem-right flexRow flexcenter gz" data-id="68000" >+ 收藏</p> </div> </div> </div> <div class=" dtl-zt"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>最新数据</p></div> </div> <div class="wkch-downs"> <div class="weekch-top flexRow"> <a class="wktpa flexRow" href="/wz/6477.html" > <img src="/jiaoben/image/noimg.png" > </a> <div class="wktpa-right flexColumn"> <a class="wktpara flexRow overflowclass" href="/wz/6477.html" >如何在asp.net2.0下面使用基于数据库(sqlserver2000)的cache</a> <a class="wktparp flexRow overflowclass" href="/wz/6477.html" > 在.NET1.1下面Cache只 </a> </div> </div> <div class="weekch-list"> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6476.html" class="weekcha flexRow flexcenter overflowclass" >在 IIS 中配置 SQL XML 支持</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6475.html" class="weekcha flexRow flexcenter overflowclass" >老外的.net与mysql存储过程编程</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6474.html" class="weekcha flexRow flexcenter overflowclass" >在asp.net中实现会话状态基础</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6473.html" class="weekcha flexRow flexcenter overflowclass" >在.net中创建使用全球唯一标识符</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6469.html" class="weekcha flexRow flexcenter overflowclass" >如何防止插入删除表造成的数据库死锁</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6468.html" class="weekcha flexRow flexcenter overflowclass" >asp.net技术的学习顺序问题</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6467.html" class="weekcha flexRow flexcenter overflowclass" >ASP.NET中数据校验部分的封装与应用</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6466.html" class="weekcha flexRow flexcenter overflowclass" >Asp.net中多彩下拉框的实现</a> </div> <div class="weekch-con flexRow"> <div class="weekch-icon flexRow"><b></b></div> <a href="/wz/6465.html" class="weekcha flexRow flexcenter overflowclass" >Web.config详解+asp.net优化</a> </div> </div> </div> </div> <div class=" dtl-wz"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>相关文章</p></div> </div> <div class="blog-list"> <a href="/wz/257494.html" class="bloga flexRow over"><p class="overflowclass">详解.NET Core如何构建一个弹性的HTTP请求机制</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257496.html" class="bloga flexRow over"><p class="overflowclass">.NET Core使用Redis实现创建分布式锁</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257498.html" class="bloga flexRow over"><p class="overflowclass">.NET内存管理释放的两种方式</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257501.html" class="bloga flexRow over"><p class="overflowclass">基于.NET8实现WinFrom应用窗口自动缩放功能</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257504.html" class="bloga flexRow over"><p class="overflowclass">浅析如何在 ASP.NET Core中实现速率限制</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257507.html" class="bloga flexRow over"><p class="overflowclass">.NET Core 委托原理解析(最新推荐)</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257509.html" class="bloga flexRow over"><p class="overflowclass">.NET 9 new features-Microsoft.ML.Tokenizers 库(文本标记化功能)</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257512.html" class="bloga flexRow over"><p class="overflowclass">如何在 .NET 中使用 Tesseract 识别图片文字</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257516.html" class="bloga flexRow over"><p class="overflowclass">ASP.NET Core Web API之Token验证的实现</p><div class="blogtime"><span>08/</span>27</div></a> <a href="/wz/257517.html" class="bloga flexRow over"><p class="overflowclass">asp.net core web api项目添加自定义中间件的实现</p><div class="blogtime"><span>08/</span>27</div></a> </div> </div> <div class="cdr-ai"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>AI精选 </p></div> <a class="jbtitle-more flexRow" href="/category/list_344_1.html" title=""><span>更多</span><b></b></a> </div> <div class="ai-list"> <div class="ail-top flexRow"> <a href="/wz/366175.html" title="" class="ailta "> <img src="https://images.jiaoben.net/uploads/20260417/logo_69e224cf789341.jpg" > <p ><span>赛博朋克 K-Pop 动画</span></p></a> <a href="/wz/366174.html" title="" class="ailta "> <img src="https://images.jiaoben.net/uploads/20260417/logo_69e224c9eb4481.jpg" > <p ><span>冰川星球大逃亡</span></p></a> </div> <div class="ail-down"> <a class="ali-con flexRow" href="/wz/366173.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">皮克斯/迪士尼风格 X (Twitter) 个人资料卡片提示</p> </a> <a class="ali-con flexRow" href="/wz/366165.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">抱着泰迪熊的男士写实肖像</p> </a> <a class="ali-con flexRow" href="/wz/365746.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">MCP协议设计与实现-第13章 Streamable HTTP:远程流式传输</p> </a> <a class="ali-con flexRow" href="/wz/365745.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">从零开发一个 MCP 服务器 + OpenCode Skill:让 AI 学会审查你的代码</p> </a> <a class="ali-con flexRow" href="/wz/365737.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">MCP协议设计与实现-第11章 Python Client 实现剖析</p> </a> <a class="ali-con flexRow" href="/wz/365731.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">MCP协议设计与实现-第14章 SSE 与 WebSocket</p> </a> <a class="ali-con flexRow" href="/wz/365730.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">MCP协议设计与实现-第7章 Prompt:可复用的交互模板</p> </a> <a class="ali-con flexRow" href="/wz/365722.html" title=""> <div class="alicon-left flexRow"><span>精选</span></div> <p class="aliconp overflowclass">MCP协议设计与实现-第8章 TypeScript Server 实现剖析</p> </a> </div> </div> </div> <div class="cdr-blog"> <div class="jb-titles flexRow"> <div class="jbtle-left flexRow"><b></b><p>脚本推荐</p></div> </div> <div class="blog-list"> <a href="/wz/zt-49225.html" title="" class="bloga flexRow over"><p class="overflowclass">SeeDance 2.0 Video Creator专区</p></a> <a href="/wz/zt-49224.html" title="" class="bloga flexRow over"><p class="overflowclass">OpenClaw AI专区</p></a> <a href="/wz/zt-49223.html" title="" class="bloga flexRow over"><p class="overflowclass">cowork专区</p></a> <a href="/wz/zt-49222.html" title="" class="bloga flexRow over"><p class="overflowclass">claude code skills专区</p></a> </div> </div> </div> </div> </div> </div> </main> <script> $(function() { // “+ 收藏”按钮点击事件 $(document).on('click', '.htmitem-right, .ztop-right', function(e) { // 仅针对包含 “+ 收藏” 文字的按钮 if ($(this).text().indexOf('+ 收藏') === -1) return; e.preventDefault(); const id = $(this).data('id'); if (!id) { layer.msg('该项暂无有效ID,无法收藏'); return; } // 构造收藏 URL: 当前域名 + /wz/zt- + id + / const bookmarkUrl = window.location.origin + '/wz/zt-' + id + '.html'; // 获取收藏标题 (优先从同级元素获取话题名称,否则使用页面标题) let bookmarkTitle = $(this).closest('.htl-item, .zttopd').find('a:first, span.overflowclass').text().trim() || document.title; if (bookmarkTitle.startsWith('#')) bookmarkTitle = bookmarkTitle.substring(1); // 浏览器收藏逻辑 (带 Fallback) try { if (window.sidebar && window.sidebar.addPanel) { // Firefox < 23 window.sidebar.addPanel(bookmarkTitle, bookmarkUrl, ""); } else if (window.external && ('AddFavorite' in window.external)) { // IE window.external.AddFavorite(bookmarkUrl, bookmarkTitle); } else { // Chrome, Safari, Firefox 23+, etc. const isMac = /Mac/i.test(navigator.userAgent); const keyStr = isMac ? 'Command + D' : 'Ctrl + D'; layer.confirm('由于浏览器安全限制,请使用 <b>' + keyStr + '</b> 手动添加收藏。<br><br>收藏地址:<br><small>' + bookmarkUrl + '</small>', { title: '收藏提示', btn: ['复制链接', '知道了'], yes: function(index) { copyToClipboard(bookmarkUrl).then(() => { layer.msg('链接已复制,请手动添加到收藏夹'); }).catch(() => { layer.msg('复制失败,请手动选择复制'); }); layer.close(index); } }); } } catch (err) { layer.msg('收藏失败,请手动添加'); } }); // 兼容非 HTTPS 的复制函数 function copyToClipboard(text) { if (navigator.clipboard && window.isSecureContext) { return navigator.clipboard.writeText(text); } else { let textArea = document.createElement("textarea"); textArea.value = text; textArea.style.position = "fixed"; textArea.style.left = "-999999px"; textArea.style.top = "-999999px"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); return new Promise((res, rej) => { document.execCommand('copy') ? res() : rej(); textArea.remove(); }); } } }); </script> <footer> <div class="foot "> <div class="foot-top flexRow"> <div class="foot-left"> <div class="ftl-top flexRow"><span class="flexRow flexcenter">脚本</span>在线</div> <p class="ftl-down"> 智能赋能梦想,脚本构筑现实。我们致力于链接AI智能指令 与传统自动化,为您提供一站式、高效率的脚 本资产与生成 服务。 </p> </div> <div class="foot-right flexRow"> <div class="ftr-list flexColumn"> <p>核心板块</p> <span>AI脚本库</span> <span>自动化仓库</span> <span>脚本实验室</span> </div> <div class="ftr-list flexColumn"> <p>关于我们</p> <a href="/category/list_229_1.html" >最新游戏</a> <span>商务合作</span> <span>隐私政策</span> </div> <div class="ftr-list flexColumn"> <p>社区支持</p> <span >API文档</span> <a href="/category/list_334_1.html" >攻略资讯</a> <span>违规举报</span> </div> </div> </div> <div class="foot-down flexColumn"> <p>© 2026 jiaoben.net | 脚本在线 | 联系:jiaobennet2026@163.com</p> <p>备案:<a style="color: #7F7F7F;" href="https://beian.miit.gov.cn/" rel="nofollow" target="_blank">湘ICP备18025217号-11</a> </p> </div> </div> </footer> <div style="display:none;"> <script> var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?5d3cfe1f36b1988029fe82a0d475b20d"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> </div> </body> </html>