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

首頁 > 編程 > .NET > 正文

ASP.NET中下載文件的幾種實例代碼

2024-07-10 12:46:20
字體:
來源:轉載
供稿:網友

代碼如下:
  //TransmitFile實現下載
    protected void Button1_Click(object sender, EventArgs e)
    {
        /*
        微軟為Response對象提供了一個新的方法TransmitFile來解決使用Response.BinaryWrite
        下載超過400mb的文件時導致Aspnet_wp.exe進程回收而無法成功下載的問題。
        代碼如下:
        */
        Response.ContentType = "application/x-zip-compressed";
        Response.AddHeader("Content-Disposition", "attachment;filename=z.zip");
        string filename = Server.MapPath("DownLoad/z.zip");
        Response.TransmitFile(filename);
    }

    //WriteFile實現下載
    protected void Button2_Click(object sender, EventArgs e)
    {
        /*
        using System.IO;

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

        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.txt";//客戶端保存的文件名
        string filePath = Server.MapPath("DownLoad/aaa.txt");//路徑

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 泽库县| 灵丘县| 石棉县| 安乡县| 临江市| 苍溪县| 麻江县| 安顺市| 义乌市| 武陟县| 西丰县| 长治市| 平塘县| 江门市| 监利县| 正宁县| 昌邑市| 玉环县| 大宁县| 会昌县| 鄢陵县| 桑日县| 兴文县| 通州区| 哈密市| 墨江| 五寨县| 达尔| 资阳市| 宣威市| 马鞍山市| 新建县| 丽水市| 巴林右旗| 阿克苏市| 茌平县| 正安县| 武鸣县| 册亨县| 老河口市| 都匀市|