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

  • 相关阅读:
    jQuery daily
    jQuery daily
    spring事务管理
    AspectJ AOP切面编程(XML配置)
    springAOP思想
    spring与web整合(交鸡肋,因为有前台框架封装了servlet)
    spring复杂对象注入四种方式
    spring的Bean注入和P标签使用
    spring Bean的作用域、生命周期和后处理器
    IoC容器实例化Bean三种方式
  • 原文地址:https://www.cnblogs.com/net2012/p/2886308.html
Copyright © 2011-2022 走看看