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

    一、下载文件

     string str = Request.QueryString["D_Url"].ToString();  //虚拟文件路径

     string str1 = str.Remove(0, str.LastIndexOf("/") + 1);

    string filePath=“~/UserFiles/”;

    filePath=System.IO.Path.Combine(filePath,str1); //将文件的物理路径和文件名称合到一块组合成完整的完整文件路径

      Response.Clear();
                    Response.ContentType = "application/octet-stream";
                    Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Server.MapPath(filePath)));
                    Response.WriteFile(filePath);
                    Response.End();

    打开文件:     string str = Request.QueryString["D_Url"].ToString();

                       string str1 = str.Remove(0, str.LastIndexOf("/") + 1);

               //string str2 = Server.MapPath("UserFiles//") + str1;   //打开文件
                    //FileInfo DownloadFile = new FileInfo(str2);
                    //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.UTF8));
                    //Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
                    //Response.WriteFile(DownloadFile.FullName);
                    //Response.Flush();
                    //Response.End();

  • 相关阅读:
    ArcGIS10新功能体验
    GP(Geoprocessing)服务的发布与调用
    ArcGIS10新体验之地图编辑
    ArcGIS10新功能之制作地图集
    推荐几本GIS专业书籍
    ArcGIS时态数据应用——动态展示台风中心轨迹
    为gridview“删除”列添加确认对话框
    (转)面向对象设计思想(C#)
    数据库Oracle与SqlServer与Access
    Oracle日期时间加减法运算
  • 原文地址:https://www.cnblogs.com/lykbk/p/lyk2342423.html
Copyright © 2011-2022 走看看