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

  • 相关阅读:
    什么叫套接字
    浅谈labviEW定时器
    C#线程篇---Task(任务)和线程池不得不说的秘密
    async与await详解
    异步编程与多线程的联系与区别
    什么是Task
    MVC模式的介绍(C#)
    Git指令
    Redis安装部署、Jedis的使用
    Oracle——序列、索引、同义词
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2011-2022 走看看