好湿?好紧?好多水好爽自慰,久久久噜久噜久久综合,成人做爰A片免费看黄冈,机机对机机30分钟无遮挡

主頁 > 知識(shí)庫 > ASP.NET批量下載文件的方法

ASP.NET批量下載文件的方法

熱門標(biāo)簽:浦發(fā)電話機(jī)器人提醒還款 電銷語音機(jī)器人型號(hào)參數(shù) 太原400電話上門辦理 昆明語音電銷機(jī)器人價(jià)格 柳州電銷機(jī)器人公司 百度地圖怎樣做地圖標(biāo)注 騰訊地圖標(biāo)注手機(jī) 400電話如何申請(qǐng)取消 征途美甲店地圖標(biāo)注

本文實(shí)例講述了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批量下載 核心代碼

復(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 + "\\\\" + tempName + ".rar");

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

復(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)方法

復(fù)制代碼 代碼如下:
/// summary>
/// 下載生成的RAR文件
/// /summary>
private void DownloadRAR(string file)
{
    FileInfo fileInfo = new FileInfo(file);
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AddHeader("Content-Disposition", "attachment;filename=" + fileInfo.Name);
    Response.AddHeader("Content-Length", fileInfo.Length.ToString());
    Response.AddHeader("Content-Transfer-Encoding", "binary");
    Response.ContentType = "application/octet-stream";
    Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
    Response.WriteFile(fileInfo.FullName);
    Response.Flush();
    string tempPath = file.Substring(0, file.LastIndexOf("\\\\"));
    //刪除臨時(shí)目錄下的所有文件
    DeleteFiles(tempPath);
    //刪除空目錄
    Directory.Delete(tempPath);
    Response.End();
}

4、DeleteFiles(string tempPath) 方法

復(fù)制代碼 代碼如下:
/// summary>
/// 刪除臨時(shí)目錄下的所有文件
/// /summary>
/// param name="tempPath">臨時(shí)目錄路徑/param>
private void DeleteFiles(string tempPath)
{
    DirectoryInfo directory = new DirectoryInfo(tempPath);
    try
    {
 foreach (FileInfo file in directory.GetFiles())
 {
     if (file.Attributes.ToString().IndexOf("ReadOnly") != -1)
     {
  file.Attributes = FileAttributes.Normal;
     }
     File.Delete(file.FullName);
 }
    }
    catch (Exception)
    {
 throw;
    }
}

希望本文所述對(duì)大家的asp.net#程序設(shè)計(jì)有所幫助。

您可能感興趣的文章:
  • ASP.NET Web Api 2實(shí)現(xiàn)多文件打包并下載文件的實(shí)例
  • ASP.NET(C#) Web Api通過文件流下載文件的實(shí)例
  • ASP.NET 在下載文件時(shí)對(duì)其重命名的思路及實(shí)現(xiàn)方法
  • asp.net C#實(shí)現(xiàn)下載文件的六種方法實(shí)例
  • ASP.NET中下載文件的幾種實(shí)例代碼
  • 在ASP.NET中下載文件的實(shí)現(xiàn)代碼
  • asp.net BackgroundWorker之在后臺(tái)下載文件
  • asp.net 下載文件時(shí)根據(jù)MIME類型自動(dòng)判斷保存文件的擴(kuò)展名
  • asp.net 下載文件時(shí)輸出文件內(nèi)容
  • asp.net Web Services上傳和下載文件(完整代碼)
  • ASP.NET實(shí)現(xiàn)從服務(wù)器下載文件問題處理

標(biāo)簽:新疆 德陽 天門 白山 江蘇 陽泉 張家界 蘭州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET批量下載文件的方法》,本文關(guān)鍵詞  ASP.NET,批量,下載,文件,的,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《ASP.NET批量下載文件的方法》相關(guān)的同類信息!
  • 本頁收集關(guān)于ASP.NET批量下載文件的方法的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 凸偷窥中国女性厕所撤尿| 欧美xxxx网站| 欧美亚洲尤物久久精品| 新婚娇嫩紧窄粗大| 极品尤物一区二区三区小说| 成人**播放1| 97影院理论午夜伦不卡手机版 | www天天干| 牛仔裤一区二区在线播放| 2020韩国理论片_HD高清在线| v电影v亚洲v欧美v国产| 久久午夜无码精品传媒有限公司| 超碰97国产公开| 欧美最猛黑人xxxx黑人猛交69| 久久黄色精品视频| free×xx性欧美漫画| 国产精品久久二区三区色裕| 隔着奶罩摸和伸进去摸哪个爽| 向涟苍士献上纯洁是第一季| 人獸交XXXⅩ欧美大片男男| 成人毛片18女人毛片免费看网站| 男男GaYGAYS?免费做污| 911嫩草亚洲精品永久一二区| 国产私拍福利精品视频51Ⅴv| www.成年人| 国产高清在线| 免费一级无码婬片AA片仙踪林 | 女人扒开腿让男人狂桶30分钟| 九九视频免费在线观看| 无码秘?人妻一区红中av| 黔西县| 国产精品午夜国产小视频| 日韩伦理电影网| jiZZjiZZ日本老师水多| 亚洲另类激情综合偷自拍图| 黄色视屏在线| 精品福利av导航| 色天天综合久久久久综合片| 亚洲888| 国产91刮伦脏话对白| 唐朝禁宫风月|