zoukankan      html  css  js  c++  java
  • jQuery以Post方式发送请求并获取返回的文件供下载!

    用ajax请求文件下载当然是可以的,不用有返回值,代码差不多是这样:

    try
            {
                string FileName = ".//doc//[大家网]Beginning.ASP.NET.2.0.E-Commerce.in.C#.2005.From.Novice.to.Professional[www.TopSage.com].pdf";
                FileName = ".//doc//Shipping+Advice+Spec++V1.4.xls";
                FullFileName = Server.MapPath(FileName); 
                //FileName--要下载的文件名 
                FileInfo DownloadFile = new FileInfo(FullFileName);
                if (DownloadFile.Exists)
                {
                    Response.Clear();
                    Response.ClearHeaders();
                    Response.Buffer = false;
                    Response.ContentType = "application/octet-stream";
                    Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.ASCII));
                    Response.AppendHeader("Content-Length", DownloadFile.Length.ToString());
                    Response.WriteFile(DownloadFile.FullName);
                    Response.Flush();
                    Response.End();
                }
                else
                {
                    //文件不存在
                }
            }
            catch
            {
               //打开时异常了
            }
    View Code
  • 相关阅读:
    iOS汇编系列-汇编入门
    C开发系列-指针
    iOS开发系列-LLVM、Clang
    java开发系列-Http协议
    iOS开发系列-SQLite
    iOS逆向系列-theos
    <Java><类加载机制><反射>
    <Java><!!!><面试题>
    <Java><修饰符>
    <Java><类与对象><OOP>
  • 原文地址:https://www.cnblogs.com/marslin/p/3138729.html
Copyright © 2011-2022 走看看