用winrar压缩文件(一)

用winrar压缩文件,提高网络传输速度,由其是从数据库导出的数据文件,效果更好.

 // 文件所在位置
   string strDirPath =  ConfigurationSettings.AppSettings["dirPath"];
//文件名用,号分割.如:aa.rar,bb.rar,cc.rar
   string[] strftpFile = ConfigurationSettings.AppSettings["ftpFile"].ToString().Split(',');


   try
   {

    for(int i=0;i<strftpFile.Length;i++)
    {   

    //得到要压缩的文件的文件名
     string strFile = strftpFile[i].Trim().Replace(".rar","").Trim() + ".txt";


     System.Diagnostics.Process Process1=new System.Diagnostics.Process();
     Process1.StartInfo.FileName=@"rar.exe";
     Process1.StartInfo.Arguments=@" a  -ep1 -inul -y  " + strDirPath + @"\"+ strftpFile[i].ToString().Trim() + "  " + strFile;//strDirPath + @"\"+strFile;
  

     Process1.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
     Process1.Start();    //进行解压
   
     while(!Process1.HasExited)          //等待压缩的完成
     {
                    
     }
     Process1.WaitForExit();
     if(Process1.ExitCode != 0)
     {

      //MessageBox.Show("压缩数据文件时出错!",Process1.ExitCode.ToString());

     }
    }


   }
   catch(Exception ex)
   {

      //MessageBox.Show("压缩数据文件时出错!",Process1.ExitCode.ToString());

   }

posted on 2007-05-22 10:20  RIVERSPIRIT  阅读(233)  评论(0)    收藏  举报