C \ # 모든 파일 을 압축 한 후 파일 을 다운로드 합 니 다.

2286 단어 파일 다운로드
  protected void Page_Load(object sender, EventArgs e)

        {



        }

        protected void btt_Click(object sender, EventArgs e)

        {

            string Path = "c:\\de";

            string resultPath = string.Empty;

            bool rel = false;

            TimeSpan nowTimeSpan = new TimeSpan();

            resultPath = YaSuo(out rel, out nowTimeSpan);

            ResponseFile(resultPath);

        }

        /// <summary>

        ///     

        /// </summary>

        /// <returns>        </returns>

        public string YaSuo(out bool bo, out TimeSpan times)

        {

            string rarurlPath = string.Empty;

            bo = false;

            //    

            string yasuoPathSave = "c:\\de\\TZ.rar";

            string yasuoPath = "c:\\de\\temp";//        

            System.Diagnostics.Process pro = new System.Diagnostics.Process();

            pro.StartInfo.FileName = @"C:\Program Files\WinRAR\WinRAR.exe";//WinRAR    

            //pro.StartInfo.Arguments = "a " + yasuoPathSave + " " + yasuoPath + " -r ";//dir       

            pro.StartInfo.Arguments = string.Format("a {0} {1} -r", yasuoPathSave, yasuoPath);

            pro.Start();

            times = pro.TotalProcessorTime;

            bo = pro.WaitForExit(60000);//     

            if (!bo)

                pro.Kill();

            pro.Close();

            pro.Dispose();

            rarurlPath = yasuoPathSave;

            return rarurlPath;

        }

        protected void ResponseFile(string filename)

        {

            FileInfo file = new FileInfo(filename);//        

            Response.Clear();//          

            Response.Charset = "GB2312";//       

            Response.ContentEncoding = Encoding.Default;//            

            Response.AddHeader("Content-Disposition", "attachment;filename=" + file.Name);

            //     。 “    /   ”        

            Response.AddHeader("Content-Length", file.Length.ToString());

            //     ,       ,              

            Response.WriteFile(file.FullName);//           

            Response.End();

        }


좋은 웹페이지 즐겨찾기