压缩文件上传并解压

//System.Web.UI.HtmlControls.HtmlInputFile fileUp,System.Web.UI.Page page
string filePath="",fileExtName="",mFileName="",mPath="";
   if("" != fileUp.PostedFile.FileName)
   {
    filePath =fileUp.PostedFile.FileName;//取得文件路径
    fileExtName= filePath.Substring(filePath.LastIndexOf(".")+1);
    try
    {
     mPath=page.Server.MapPath(@"../UpFiles/");
     mFileName=filePath.Substring(filePath.LastIndexOf("\\")+1);;//取得文件名
     int index=mFileName.LastIndexOf(".");
                    fileExtName=mFileName.Substring(0,index);
     fileUp.PostedFile.SaveAs(mPath + mFileName);

     Process p = new Process();  
     p.StartInfo.UseShellExecute = false;  
     p.StartInfo.RedirectStandardInput = true;  
     p.StartInfo.RedirectStandardOutput = true;  
     p.StartInfo.RedirectStandardError = true;  
     p.StartInfo.CreateNoWindow = true; 
     p.StartInfo.FileName = "cmd.exe";  
     p.Close();  
     //解压Rar文件 
     string pa=mPath+  mFileName;
     System.Diagnostics.Process Process1=new Process(); 
     Process1.StartInfo.FileName=mPath+"//Rar.exe"; 
   
     Process1.StartInfo.Arguments=" x -inul -y "+pa+" "+mPath+""; 

    // Process1.StartInfo.Arguments=" x -inul -y "+mPath+" "+mPath+""; 
     Process1.Start();//解压开始 
     while(!Process1.HasExited)           //等待解压的完成 
     { 
    
     } 
    
     File.Delete(pa);//删除rar文件 
    }
    catch(Exception ex)
    {
     throw new Exception(""+ex.Message +"");
    }
   }
   mPath=page.Server.MapPath(@"../UpFiles");
   return mPath+"\\"+fileExtName;//返回路径

转载于:https://www.cnblogs.com/wuyq80/articles/375899.html

你可能感兴趣的:(压缩文件上传并解压)