• <fieldset id="8imwq"><menu id="8imwq"></menu></fieldset>
  • <bdo id="8imwq"><input id="8imwq"></input></bdo>
    最新文章專題視頻專題問答1問答10問答100問答1000問答2000關(guān)鍵字專題1關(guān)鍵字專題50關(guān)鍵字專題500關(guān)鍵字專題1500TAG最新視頻文章推薦1 推薦3 推薦5 推薦7 推薦9 推薦11 推薦13 推薦15 推薦17 推薦19 推薦21 推薦23 推薦25 推薦27 推薦29 推薦31 推薦33 推薦35 推薦37視頻文章20視頻文章30視頻文章40視頻文章50視頻文章60 視頻文章70視頻文章80視頻文章90視頻文章100視頻文章120視頻文章140 視頻2關(guān)鍵字專題關(guān)鍵字專題tag2tag3文章專題文章專題2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章專題3
    問答文章1 問答文章501 問答文章1001 問答文章1501 問答文章2001 問答文章2501 問答文章3001 問答文章3501 問答文章4001 問答文章4501 問答文章5001 問答文章5501 問答文章6001 問答文章6501 問答文章7001 問答文章7501 問答文章8001 問答文章8501 問答文章9001 問答文章9501
    當(dāng)前位置: 首頁 - 科技 - 知識(shí)百科 - 正文

    asp.net中文件下載功能的實(shí)例代碼

    來源:懂視網(wǎng) 責(zé)編:小采 時(shí)間:2020-11-27 22:41:13
    文檔

    asp.net中文件下載功能的實(shí)例代碼

    asp.net中文件下載功能的實(shí)例代碼: 代碼如下://TransmitFile實(shí)現(xiàn)下載protected void Button1_Click(object sender, EventArgs e){ Response.ContentType = application/x-zip-compressed;Response.AddHeader(Content-Disposition
    推薦度:
    導(dǎo)讀asp.net中文件下載功能的實(shí)例代碼: 代碼如下://TransmitFile實(shí)現(xiàn)下載protected void Button1_Click(object sender, EventArgs e){ Response.ContentType = application/x-zip-compressed;Response.AddHeader(Content-Disposition

    代碼如下:
    //TransmitFile實(shí)現(xiàn)下載
    protected void Button1_Click(object sender, EventArgs e)
    {


    Response.ContentType = "application/x-zip-compressed";
    Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");
    string filename = Server.MapPath("DownLoad/aaa.zip");
    Response.TransmitFile(filename);
    }

    //WriteFile實(shí)現(xiàn)下載
    protected void Button2_Click(object sender, EventArgs e)
    {


    string fileName ="aaa.zip";//客戶端保存的文件名
    string filePath=Server.MapPath("DownLoad/aaa.zip");//路徑

    FileInfo fileInfo = new FileInfo(filePath);
    Response.Clear();
    Response.ClearContent();
    Response.ClearHeaders();
    Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
    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();
    Response.End();
    }

    //WriteFile分塊下載
    protected void Button3_Click(object sender, EventArgs e)
    {

    string fileName = "aaa.zip";//客戶端保存的文件名
    string filePath = Server.MapPath("DownLoad/aaa.zip");//路徑

    System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath);

    if (fileInfo.Exists == true)
    {
    const long ChunkSize = 102400;//100K 每次讀取文件,只讀取100K,這樣可以緩解服務(wù)器的壓力
    byte[] buffer = new byte[ChunkSize];

    Response.Clear();
    System.IO.FileStream iStream = System.IO.File.OpenRead(filePath);
    long dataLengthToRead = iStream.Length;//獲取下載的文件總大小
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));
    while (dataLengthToRead > 0 && Response.IsClientConnected)
    {
    int lengthRead = iStream.Read(buffer, 0, Convert.ToInt32(ChunkSize));//讀取的大小
    Response.OutputStream.Write(buffer, 0, lengthRead);
    Response.Flush();
    dataLengthToRead = dataLengthToRead - lengthRead;
    }
    Response.Close();
    }
    }

    //流方式下載
    protected void Button4_Click(object sender, EventArgs e)
    {
    string fileName = "aaa.zip";//客戶端保存的文件名
    string filePath = Server.MapPath("DownLoad/aaa.zip");//路徑

    //以字符流的形式下載文件
    FileStream fs = new FileStream(filePath, FileMode.Open);
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    Response.ContentType = "application/octet-stream";
    //通知瀏覽器下載文件而不是打開
    Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
    Response.BinaryWrite(bytes);
    Response.Flush();
    Response.End();

    }

    聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com

    文檔

    asp.net中文件下載功能的實(shí)例代碼

    asp.net中文件下載功能的實(shí)例代碼: 代碼如下://TransmitFile實(shí)現(xiàn)下載protected void Button1_Click(object sender, EventArgs e){ Response.ContentType = application/x-zip-compressed;Response.AddHeader(Content-Disposition
    推薦度:
    標(biāo)簽: 下載 文件 下載的
    • 熱門焦點(diǎn)

    最新推薦

    猜你喜歡

    熱門推薦

    專題
    Top
    主站蜘蛛池模板: 国产精品欧美亚洲韩国日本| 欧美一区二区精品久久| 精品久久人妻av中文字幕| 99久久婷婷国产综合精品草原| 日韩精品一区二区三区色欲AV| 国语自产精品视频| 久久精品国产影库免费看| 欧美精品中文字幕亚洲专区| 精品中文高清欧美| 中日韩产精品1卡二卡三卡| 九九热在线精品视频| 国产精品九九久久免费视频 | 欧美亚洲综合免费精品高清在线观看 | 日韩精品久久久久久免费| 久久国产精品国语对白| 日韩精品在线视频| 国产99视频精品免视看7| 无码囯产精品一区二区免费| 日韩精品中文字幕第2页| 国产天天综合永久精品日| 亚洲精品成人av在线| 国产精品黄网站| 996久久国产精品线观看| 精品无人码麻豆乱码1区2区| 亚洲国产精品无码久久久秋霞2 | 精品日韩亚洲AV无码一区二区三区| 无码国产亚洲日韩国精品视频一区二区三区| 国产叼嘿久久精品久久| 91av国产精品| 2023国产精品自拍| 中文精品久久久久国产网址 | 国产精品丝袜一区二区三区| 亚洲AV成人精品一区二区三区| 亚洲国模精品一区| 亚洲精品无码久久久| 西瓜精品国产自在现线| 日本精品久久久久影院日本 | 欧美日韩国产成人高清视频,欧美日韩在线精品一 | 国产成人精品亚洲精品| 成人精品一区二区三区电影黑人 | 国产精品va无码一区二区|