zoukankan      html  css  js  c++  java
  • 后台下载文件代码

     FileInfo fi = new FileInfo(fileName);//excelFile为文件在服务器上的地址
                        HttpResponse contextResponse = HttpContext.Current.Response;
                        contextResponse.Clear();
                        contextResponse.Buffer = true;
                        contextResponse.Charset = "UTF8"; //设置了类型为中文防止乱码的出现 
                        string downloadName = month.Replace("/", "") + "月份客运设备设备设施维护管理表.xls";
                        string broswer = context.Request.UserAgent.ToLower();
                        if (broswer.IndexOf("msie") > -1
                            || broswer.IndexOf("edge") > -1
                            || broswer.IndexOf("like gecko") > -1) 
                        { 
                            downloadName = HttpUtility.UrlPathEncode(downloadName); 
                        } 
                        contextResponse.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", downloadName)); //定义输出文件和文件名 
                        contextResponse.AppendHeader("Content-Length", fi.Length.ToString());
                        contextResponse.ContentEncoding = Encoding.UTF8;
                        contextResponse.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
                        //HttpContext.Current.Server.UrlEncode()
                       
                        contextResponse.WriteFile(fi.FullName);
                        contextResponse.Flush();
                        context.ApplicationInstance.CompleteRequest();

     FileInfo fi = new FileInfo(fileName);//excelFile为文件在服务器上的地址                    HttpResponse contextResponse = HttpContext.Current.Response;                    contextResponse.Clear();                    contextResponse.Buffer = true;                    contextResponse.Charset = "UTF8"; //设置了类型为中文防止乱码的出现                     string downloadName = month.Replace("/", "年") + "月份客运设备设备设施维护管理表.xls";                    string broswer = context.Request.UserAgent.ToLower();                    if (broswer.IndexOf("msie") > -1                        || broswer.IndexOf("edge") > -1                        || broswer.IndexOf("like gecko") > -1)                     {                         downloadName = HttpUtility.UrlPathEncode(downloadName);                     }                     contextResponse.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", downloadName)); //定义输出文件和文件名                     contextResponse.AppendHeader("Content-Length", fi.Length.ToString());                    contextResponse.ContentEncoding = Encoding.UTF8;                    contextResponse.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。                     //HttpContext.Current.Server.UrlEncode()                                       contextResponse.WriteFile(fi.FullName);                    contextResponse.Flush();                    context.ApplicationInstance.CompleteRequest();

  • 相关阅读:
    普元EOS中nui(对jquery MiniUi的封装)合并表头
    css--让箭头动起来
    在开发中说一说你最讨厌什么函数????
    前端开发学习路线
    默哀日,网页置灰,开发人员你应该掌握的
    window--环境下升级node的版本(因为低版本node运行Vue项目有问题)
    小程序--模板<template>的定义和使用
    小程序--app.js之App方法
    小程序---页面配置文件,只对自己的页面有效果
    javascript 内存模型
  • 原文地址:https://www.cnblogs.com/daimaxuejia/p/12765531.html
Copyright © 2011-2022 走看看