前面有生成Excel或Word的示例,所以就不再重新写了。

这里只提供将指定文件以ZIP的方式下载。

创建一个 Zip工具类 

public class ZIPCompressUtil
    {
        public static byte[] Zip(List<string> AllFilesPath)
        {
            try
            {
                if (AllFilesPath.Count > 0)
                {
                    MemoryStream ms = new MemoryStream();
                    byte[] buffer = null;

                    using (ZipFile file = ZipFile.Create(ms))
                    {
                        file.BeginUpdate();
                        file.NameTransform = new MyNameTransfom();
//通过这个名称格式化器,可以将里面的文件名进行一些处理。默认情况下,会自动根据文件的路径在zip中创建有关的文件夹。  

                        for (int i = 0; i < AllFilesPath.Count; i++)
                        {
                            string strFile = AllFilesPath[i];
                            file.Add(strFile);
                        }


                        file.CommitUpdate();

                        buffer = new byte[ms.Length];
                        ms.Position = 0;
                        ms.Read(buffer, 0, buffer.Length);
                    }
                    return buffer;
                   
                }
                return null;
            }
            catch
            {
                return null;
            }

        }
}
View Code

相关文章:

  • 2022-03-04
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-02-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-02
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2021-07-27
相关资源
相似解决方案