清清月儿 .NET万花筒 Asp.net技术 Asp.net教程 Asp.net源码 Asp.net基础 Asp.net控件 Asp.net入门

天下事有难易乎?为之,则难者亦易矣;不为,则易者亦难矣。

原创 asp.net利用RAR实现文件压缩解压缩【月儿原创】 收藏

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

作者:清清月儿

主页:http://blog.csdn.net/21aspnet/           时间:2007.6.13

如果服务器上安装了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());
        }

    }

}

服务器端目录:

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

发表于 @ 2007年06月13日 00:16:00|评论(loading...)

新一篇: C#优化字符串操作【月儿原创】 | 旧一篇: asp.net的Ajax学习进阶【月儿原创】

用户操作
[即时聊天] [发私信] [加为好友]
清清月儿
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
清清月儿的公告
文章分类
收藏
    .NET 工具
    C# to VB.NET Translator
    Fiddler
    FxCop代码标准检测工具
    httpwatch
    ieinspector
    IETester
    Memcached
    Multiple IE
    Nbear
    Nunit单元测试
    pushlets
    Tab集合
    VB.NET and C# Comparison
    VB.NET 代码转为C#
    网站国际排名查询工具
    .NET 下载/讲座视频
    chinaitlab
    enfull
    Visual Studio 2005 的工具
    wrox出版社书刊代码下载
    中国台湾微软MSDN
    中文MSDN WebCast网络广播全部下载列表
    源码之家
    .NET 优秀Blog
    cathsfz
    cnkiminzhuhu
    cuike519的专栏
    dahuzizyd的专栏
    DotNet技术交流乐园
    DotNet男孩社区
    dudu
    gztoby
    IT Crazy
    Kemin's booootLog
    kimyoo(RSS)
    Leoo2sk
    LoveCherry
    MSDN每日追踪
    Nios.Org
    phphot
    Teddy's Knowledge Base
    Think Different and Think More
    Visual Studio.net专栏
    WCF Tools 中国研发团队的专栏
    体验ASP.NET 2.0新特性
    刘洪峰
    天轰穿
    孟宪会
    宝玉
    开心就好【博客堂】
    张子阳
    彭斌
    思归呓语
    木子 [I am praying]
    李会军
    李洪根【VB】
    永春阁
    汉飞扬【Vista】
    涂曙光【SharePoint】
    理想&美人(RSS)
    维生素C.net
    网际浪子
    葛涵涛
    蒋涛
    蝈蝈俊.net[csdn版]
    蝈蝈俊.net[joycode版]
    谭振林
    邹建
    阿不
    阿良.NET
    雨痕
    風語·深蓝
    鸟食轩(RSS)
    黄昕
    .NET 优秀网站
    .NET 官方网www.asp.net
    .NET 藏经阁 - 知识分享
    .NET开发资源精华收【不得不看】
    ASP .NET FAQ
    asp101
    aspfree
    C#开源资源
    C#开源资源大全
    C#语言在线帮助网站
    codeproject
    infragistics
    Internet Explorer 开发者资源
    iwebsms
    MSDN Web/服务
    MSDN中文
    Scott Guthrie(ASP.NET之父)
    SharePoint爱好者
    VS2005.com
    Wintellect
    www.411asp.net
    世界上最大的Open Source项目在线网站
    中国C#技术学习中心
    官方ASP.NET入门教程
    微软中文新闻组
    微软官方.NET指导站点
    最好的索引网站
    正则
    邮件发送常见问题解决方法
    Ajax链接
    AJAX载入等待图片在线生成
    bindows(RSS)
    DHTML menu4作者主页(RSS)
    Dhtmlgoodies
    Dynamicdrive
    EXT类库
    json
    Tabs
    Tabs
    Tabs
    Yahoo YUI
    大量DHTML代码
    无忧脚本 - JavaScript
    索漫
    综合开发技术网
    CSDN
    IBM中文Web 项目资源中心
    W3C技术在中国
    中国BS网
    中文C#技术站
    天新网
    天极网开发频道
    太平洋电脑网web开发
    看雪
    统一教学网
    编程爱好者
    网页设计师:web标准教程及推广,网站重构
    老猫理想
    蓝色理想
    豆豆技术网
    赛迪网
    存档
    软件项目交易
    Csdn Blog version 3.1a
    Copyright © 清清月儿