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

    public void DownLoad(string FileName,Page R)
      
    {
       
    if (FileName != "")
       
    {
        
    string path = R.Server.MapPath(FileName);
        System.IO.FileInfo file 
    = new System.IO.FileInfo(path);
        
    if (file.Exists)
        
    {
         R.Response.Clear();
         R.Response.AddHeader(
    "Content-Disposition""attachment; FileName=" + file.Name);
         R.Response.AddHeader(
    "Content-Length", file.Length.ToString());
         R.Response.ContentType 
    = "application/octet-stream";
         R.Response.Filter.Close();
         R.Response.WriteFile(file.FullName);         
         R.Response.End();
        }

        
    else
        
    {
         R.Response.Write(
    "This file does not exist.");
        }


       }

    示例 二:

    private void NewDownLoad(string Path,string FileName)
            
    {//Path为文件绝对路径,FileName为文件路径
                FileStream fs=new FileStream(Path,FileMode.Open,FileAccess.Read);
                BinaryReader r
    =new BinaryReader(fs);
                Response.AddHeader(
    "Content-Disposition","attachment;filename="+FileName);
                Response.Charset
    ="gb2312";
                Response.ContentType
    ="application/octet-stream";
                Response.BinaryWrite(r.ReadBytes(Convert.ToInt32(fs.Length)));
                Response.Flush();
                fs.Close();
                
    try
                
    {
                    File.Delete(Path);
                }

                
    catch(System.Exception ee)
                
    {
                    
    string ff=ee.ToString();
                }

            }
    示例三:
    文件下载
  • 相关阅读:
    C语言实现两栈空间共享
    MyEclipse里项目部署到tomcat上之后,tomcat webpps文件夹里为什么找不到这个项目
    CSS选择器
    用友2016成都校园招聘笔试题
    windows、ubuntu下eclipse搭建java、Python环境问题总结
    ubuntu上用eclipse搭建java、python开发环境
    windows 下用eclipse搭建java、python开发环境
    简单事件机制的研究
    软件测试(软件安装:php+mysql+apache+mantis过程遇到的问题以及解决方法)
    4、总结一下,以软件开发生命周期来说明测试的使用情况。
  • 原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
Copyright © 2011-2022 走看看