FileDown.cs

(开头部分) 6KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.IO;
using System.Threading;
using System.Web;

/// <summary>
/// 文件下载类
/// </summary>
public class FileDown
{
    public FileDown()
    { }

    /// <summary>
    /// 参数为虚拟路径
    /// </summary>
    public static string FileNameExtension(string FileName)
    {
        return Path.GetExtension(MapPathFile(FileName));
    }

    /// <summary>
    /// 获取物理地址
    /// </summary>
    public static string MapPathFile(string FileName)
    {
        return HttpContext.Current.Server.MapPath(FileName);
    }

    /// <summary>
    /// 普通下载
    /// </summary>
    /// <param name="FileName">文件虚拟路径</param>
    public static void DownLoadold(string FileName)
    {
        string destFileName = MapPathFile(FileName);
        if (File.Exists(destFileName))
        {
            FileInfo fi = new FileInfo(destFileName);
            HttpContext.Current.Response.Clear();
            HttpContext.Current.Response.ClearHeaders();
            HttpContext.Current.Response.Buffer = false;
            HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(destFileName), System.Text.Encoding.UTF8));
            HttpContext.Current.Response.AppendHeader("Content-Length", fi.Length.ToString());
            HttpContext.Current.Response.ContentType = "application/octet-stream";
            HttpContext.Current.Response.WriteFile(destFileName);
            HttpContext.Current.Response.Flush();
            HttpContext.Current.Response.End();
        }
    }

    /// <summary>
    /// 分块下载
    /// </summary>
    /// <param name="FileName">文件虚拟路径</param>
    public static void DownLoad(string FileName)
    {
        string filePath = MapPathFile(FileName);
        long chunkSize = 204800;             //指定块大小 
        byte[] buffer = new byte[chunkSize]; //建立一个200K的缓冲区 
后面还有 120 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。