• 文件下载源码


    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();
                }

            }
    示例三:
    文件下载
  • 相关阅读:
    LOJ6433 [PKUSC2018] 最大前缀和 【状压DP】
    [NOIP2017] 宝藏 【树形DP】【状压DP】
    51Nod1824 染色游戏 【Lucas定理】【FMT】【位运算】
    51Nod1778 小Q的集合 【组合数】【Lucas定理】
    LOJ6436 [PKUSC2018] 神仙的游戏 【FFT】
    LOJ6432 [PKUSC2018] 真实排名 【组合数】
    BZOJ5210 最大连通子块和 【树链剖分】【堆】【动态DP】
    LOJ2269 [SDOI2017] 切树游戏 【FWT】【动态DP】【树链剖分】【线段树】
    洛谷3707 [SDOI2017] 相关分析 【线段树】
    RBAC
  • 原文地址:https://www.cnblogs.com/sunheyubo/p/881677.html
Copyright © 2020-2023  润新知