zoukankan      html  css  js  c++  java
  • ASP.NET下载文件 . 天高地厚

    using System.IO;
        'FilePath - Refers to Full Path of the file
            protected void DownloadFile(string FilePath)
            {
                // Gets the File Name
                string fileName = FilePath.Substring(FilePath.LastIndexOf('\\') + 1);
                byte[] buffer;

                using (FileStream fileStream = new FileStream(FilePath, FileMode.Open))
                {
                    int fileSize = (int)fileStream.Length;
                    buffer = new byte[fileSize];
                    // Read file into buffer
                    fileStream.Read(buffer, 0, (int)fileSize);
                }
                Response.Clear();
                Response.Buffer = true;
                Response.BufferOutput = true;
                Response.ContentType = "application/x-download";
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
                Response.CacheControl = "public";
                // writes buffer to OutputStream
                Response.OutputStream.Write(buffer, 0, buffer.Length);
                Response.End();
            }

  • 相关阅读:
    汇编笔记(1) 寄存器
    阿里云RDS数据库备份文件恢复到本地数据库
    Java调用HTTPS接口的证书配置
    SQL面试题之行转列
    WebsiteCrawler
    supervisor
    简单学习github代码托管
    [egret+pomelo]实时对战游戏杂记(5)
    [egret+pomelo]实时游戏杂记(4)
    [egret+pomelo]实时游戏杂记(3)
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2011-2022 走看看