博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET 下载文件代码块
阅读量:4697 次
发布时间:2019-06-09

本文共 921 字,大约阅读时间需要 3 分钟。

/// <summary>

/// 普通下载
/// </summary>
/// <param name="FileName">文件虚拟路径</param>
public static void DownLoadold(string FileName)
{
    string destFileName = FileName; //MapPathFile(FileName);
    if (File.Exists(destFileName))
    {
        FileInfo fi = new FileInfo(destFileName);
        HttpContext.Current.Response.Clear();
        HttpContext.Current.Response.ClearHeaders();
        HttpContext.Current.Response.Buffer = false;
        HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8));
        HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
        HttpContext.Current.Response.ContentType = "application/octet-stream";
        HttpContext.Current.Response.WriteFile(destFileName);
        HttpContext.Current.Response.Flush();
        HttpContext.Current.Response.End();
    }
}

转载于:https://www.cnblogs.com/zhenpingwang/archive/2013/04/19/3030663.html

你可能感兴趣的文章
Adobe® Reader®.插件开发
查看>>
【POJ 3461】Oulipo
查看>>
Alpha 冲刺 (5/10)
查看>>
使用Siege进行WEB压力测试
查看>>
斑马为什么有条纹?
查看>>
android多层树形结构列表学习笔记
查看>>
Android_去掉EditText控件周围橙色高亮区域
查看>>
《构建之法》第一、二、十六章阅读笔记
查看>>
arrow:让Python的日期与时间变的更好
查看>>
(转)Excel的 OleDb 连接串的格式(连接Excel 2003-2013)
查看>>
Java并发编程
查看>>
Git Stash用法
查看>>
sql server 2008学习8 sql server存储和索引结构
查看>>
Jquery radio选中
查看>>
postgressql数据库中limit offset使用
查看>>
测试思想-集成测试 关于接口测试 Part 2
查看>>
php生成器使用总结
查看>>
T-SQL中的indexof函数
查看>>
javascript基础之数组(Array)对象
查看>>
mysql DML DDL DCL
查看>>