zoukankan      html  css  js  c++  java
  • C# 下载文件 只利用文件的存放路径来下载

    第一种方式:
    最简单的就是返回一个file类型的数据即FilePathResult类型的对象

                 string serverPath = ConfigurationManager.AppSettings["file.disk.path"];
                 string name = Path.GetFileName(path);
                 return File(serverPath + path, mime, name);
    

    第二种方式:

                string serverPath = ConfigurationManager.AppSettings["file.disk.path"];
    
                FileInfo file = new FileInfo(serverPath + path);
                if (file.Exists)
                {
                    Response.ClearContent();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + file.Name);
                    Response.AddHeader("Content-Length", file.Length.ToString());
                    Response.ContentType = "text/plain";
                    Response.TransmitFile(file.FullName);
                    Response.End();
                }
    
  • 相关阅读:
    工厂方法模式
    代理模式
    观察者模式
    策略模式
    单例模式
    简单工厂模式
    lintcode:等价二叉树
    lintcode:被围绕的区域
    lintcode:二叉树的所有路径
    lintcode:快乐数
  • 原文地址:https://www.cnblogs.com/ylzhang/p/6874928.html
Copyright © 2011-2022 走看看