zoukankan      html  css  js  c++  java
  • 文件打包下载

    使用的dll:ICSharpCode.SharpZipLib

    下载地址 http://www.icsharpcode.net/OpenSource/SharpZipLib/Download.aspx

    /// <summary>
    /// 下载资料
    /// </summary>
    public void DownloadCourseData()
    {
        string attachBatchNo = DESHelper.Decrypt(ctx.Get("no"), "simpo");//附件批次号
        List<Edu_Attach> edu_AttachList = edu_AttachService.FindAttByNo(attachBatchNo);//获取附件集合
        if (edu_AttachList.Count > 0)
        {
            string pathName = edu_AttachList[0].AttachContent;//附件路径
            int pos = pathName.LastIndexOf("/");
            string path = pathName.Substring(0, pos + 1);//路径不含文件名
            string zipName = DateTime.Now.ToString("yyyyMMddHHmmssfff") + strUtil.GetRnd(4, true, false, false, false, "") + ".zip";//zip文件名
            string zipPathName = PathHelper.Map(sys.Path.DiskPhoto) + path.Replace("/static/upload/image", "").Replace("/", "\") + zipName;
            FileStream fs = new FileStream(zipPathName, FileMode.Create);
            ZipOutputStream zos = new ZipOutputStream(fs);
            foreach (Edu_Attach edu_Attach in edu_AttachList)
            {
                string filePathName = PathHelper.Map(sys.Path.DiskPhoto) + edu_Attach.AttachContent.Replace("/static/upload/image", "").Replace("/", "\");
                pos = filePathName.LastIndexOf("\");
                string zipEntryName = edu_Attach.AttachName;
                ZipEntry zipEntry = new ZipEntry(zipEntryName);
                zos.PutNextEntry(zipEntry);
                fs = File.OpenRead(filePathName);
                byte[] byteArray = new byte[fs.Length];
                fs.Read(byteArray, 0, byteArray.Length);
                zos.Write(byteArray, 0, byteArray.Length);
            }
            zos.Finish();
            zos.Close();
            string downloadFileName = path + zipName;
            redirectUrl(downloadFileName);
        }
    }
    View Code
  • 相关阅读:
    原创 动态卷积
    BZOJ1565 植物大战僵尸
    BZOJ1143 [CTSC2008] 祭祀river
    BZOJ3438 小M的作物
    BZOJ3144 [HNOI2013]切糕
    BZOJ2039 [2009国家集训队]employ人员雇佣
    BZOJ1066[SCOI2007]蜥蜴
    BZOJ3874 codevs3361 宅男计划
    Codeforces Round #343 (Div. 2)
    [转]后缀自动机(SAM)
  • 原文地址:https://www.cnblogs.com/s0611163/p/3601935.html
Copyright © 2011-2022 走看看