asp.net上传RAR文件自动解压

None.gif using  System;
None.gif
using  System.IO;
None.gif
using  System.Diagnostics;
None.gif
using  System.Collections;
None.gif
using  System.ComponentModel;
None.gif
using  System.Data;
None.gif
using  System.Drawing;
None.gif
using  System.Web.Security;
None.gif
using  System.Web;
None.gif
using  System.Web.SessionState;
None.gif
using  System.Web.UI;
None.gif
using  System.Web.UI.WebControls;
None.gif
using  System.Web.UI.HtmlControls;
None.gif
namespace  WebLayer
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif
/**//// <summary>
InBlock.gif
/// WebForm1 的摘要说明。
ExpandedSubBlockEnd.gif
/// </summary>

InBlock.gifpublic class WebForm1 : System.Web.UI.Page
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif  
protected System.Web.UI.WebControls.Button Button1;
InBlock.gif  
protected System.Web.UI.HtmlControls.HtmlInputFile myfile;
InBlock.gif
InBlock.gif  
private void Page_Load(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
// 在此处放置用户代码以初始化页面
ExpandedSubBlockEnd.gif
  }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif  
Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
InBlock.gif  
override protected void OnInit(EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
//
InBlock.gif   
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
InBlock.gif   
//
InBlock.gif
   InitializeComponent();
InBlock.gif   
base.OnInit(e);
ExpandedSubBlockEnd.gif  }

InBlock.gif  
ExpandedSubBlockStart.gifContractedSubBlock.gif  
/**//// <summary>
InBlock.gif  
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
InBlock.gif  
/// 此方法的内容。
ExpandedSubBlockEnd.gif  
/// </summary>

InBlock.gif  private void InitializeComponent()
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{    
InBlock.gif   
this.Button1.Click += new System.EventHandler(this.Button1_Click);
InBlock.gif   
this.Load += new System.EventHandler(this.Page_Load);
InBlock.gif
ExpandedSubBlockEnd.gif  }

ExpandedSubBlockEnd.gif  
#endregion

InBlock.gif
InBlock.gif  
private void Button1_Click(object sender, System.EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif  
dot.gif{
InBlock.gif   
string path = @"C:\"+myfile.PostedFile.FileName.Substring(myfile.PostedFile.FileName.LastIndexOf("\\"));
InBlock.gif   myfile.PostedFile.SaveAs(path);
InBlock.gif   Response.Write(
"文件上传成功:"+path);
InBlock.gif   
//Response.End();
InBlock.gif   
// 在此处放置用户代码以初始化页面  
InBlock.gif
   Process p = new Process();   
InBlock.gif   p.StartInfo.UseShellExecute 
= false;   
InBlock.gif   p.StartInfo.RedirectStandardInput 
= true;   
InBlock.gif   p.StartInfo.RedirectStandardOutput 
= true;   
InBlock.gif   p.StartInfo.RedirectStandardError 
= true;   
InBlock.gif   p.StartInfo.CreateNoWindow 
= true;  
InBlock.gif   p.StartInfo.FileName 
= "cmd.exe";   
InBlock.gif   p.Close();   
InBlock.gif   
//解压Rar文件  
InBlock.gif
   string ServerDir=@"C:\Program Files\WinRAR";//rar路径  
InBlock.gif
   System.Diagnostics.Process Process1=new Process();  
InBlock.gif   Process1.StartInfo.FileName
=ServerDir+"\\Rar.exe";  
InBlock.gif   Directory.CreateDirectory(path
+".files"); //创建解压文件夹  
InBlock.gif
   Process1.StartInfo.Arguments=" x -inul -y "+path+" "+path+".files";  
InBlock.gif   Process1.Start();
//解压开始  
InBlock.gif
   while(!Process1.HasExited)           //等待解压的完成  
ExpandedSubBlockStart.gifContractedSubBlock.gif
   dot.gif{  
ExpandedSubBlockEnd.gif   }
  
InBlock.gif   
//File.Delete(path);//删除rar文件  
ExpandedSubBlockEnd.gif
  }

ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}

None.gif
None.gif

转载于:https://www.cnblogs.com/oflying907/archive/2006/04/15/375749.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值