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();
            }

  • 相关阅读:
    DOS批量递归删除文件夹
    根据关键词kill进程
    docker创建镜像的几个命令
    OpenSSL命令---passwd
    A configuration with this name already exists
    查看Linux版本
    ubuntu初次安装后设置root用户密码
    [转载]气象数据集下载网站(包括中国700多个站)
    将界面从屏幕外拖回来方法
    使用GitHub分享代码
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2011-2022 走看看