国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 學(xué)院 > 開發(fā)設(shè)計(jì) > 正文

ASP.NET批量下載文件

2019-11-17 01:51:15
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

asp.net批量下載文件

一、實(shí)現(xiàn)步驟

  在用戶操作界面,由用戶選擇需要下載的文件,系統(tǒng)根據(jù)所選文件,在服務(wù)器上創(chuàng)建用于存儲(chǔ)所選文件的臨時(shí)文件夾,將所選文件拷貝至臨時(shí)文件夾。然后調(diào)用 RAR程序,對(duì)臨時(shí)文件夾進(jìn)行壓縮,然后輸出到客戶端。最后刪除臨時(shí)文件夾。

二、代碼實(shí)現(xiàn)

1、ASP.NET批量下載 核心代碼C# 代碼 復(fù)制
//遍歷服務(wù)器指定文件夾下的所有文件            string path = "uploads/Image/";            string serverPath = Server.MapPath(path);            //創(chuàng)建臨時(shí)文件夾            string tempName = DateTime.Now.ToString("yyyyMMddHHMMss");            string tempFolder = Path.Combine(serverPath, tempName);            Directory.CreateDirectory(tempFolder);            DirectoryInfo folder = new DirectoryInfo(serverPath);            foreach (FileInfo file in folder.GetFiles())            {                string filename = file.Name;                File.Copy(serverPath + "/" + filename, tempFolder + "/" + filename);            }            //ZKHelper.JSHelper.Alert("圖片拷貝成功!");            //產(chǎn)生RAR文件,及文件輸出            RARSave(tempFolder, tempName);            DownloadRAR(tempFolder + "http:////" + tempName + ".rar");

2、RARSave(string tempFolder, string tempName) 方法

C# 代碼 復(fù)制
/// <summary>        /// 生成RAR文件        /// </summary>        /// <param name="path">存放復(fù)制文件的目錄</param>        /// <param name="rarPatch">RAR文件存放目錄</param>        /// <param name="rarName">RAR文件名</param>        PRivate void RARSave(string rarPatch, string rarName)        {            string the_rar;            RegistryKey the_Reg;            Object the_Obj;            string the_Info;            ProcessStartInfo the_StartInfo;            Process the_Process;            try            {                the_Reg = Registry.ClassesRoot.OpenSubKey(@"WinRAR");                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 " + rarName + " -r";                the_StartInfo = new ProcessStartInfo();                the_StartInfo.FileName = "WinRar";//the_rar;                the_StartInfo.Arguments = the_Info;                the_StartInfo.WindowStyle = ProcessWindowStyle.Hidden;                //打包文件存放目錄                the_StartInfo.WorkingDirectory = rarPatch;                the_Process = new Process();                the_Process.StartInfo = the_StartInfo;                the_Process.Start();                the_Process.WaitForExit();                the_Process.Close();            }            catch (Exception)            {                throw;            }        }

3、DownloadRAR(string file)方法

C# 代碼 復(fù)制

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 姚安县| 大关县| 香河县| 谢通门县| 渝中区| 且末县| 双辽市| 岑巩县| 临江市| 枣强县| 临武县| 论坛| 道孚县| 张家界市| 嘉祥县| 广河县| 犍为县| 龙游县| 珲春市| 永德县| 湖口县| 灵山县| 定日县| 喀什市| 台江县| 哈巴河县| 汽车| 丹寨县| 乌海市| 延庆县| 乃东县| 三明市| 亚东县| 曲周县| 灵川县| 浪卡子县| 桐城市| 临泉县| 浠水县| 舞阳县| 内黄县|