99
This commit is contained in:
36
Reportapi/MyCode.Project.Infrastructure/Common/ZipHelper.cs
Normal file
36
Reportapi/MyCode.Project.Infrastructure/Common/ZipHelper.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MyCode.Project.Infrastructure.Common
|
||||
{
|
||||
public class ZipHelper
|
||||
{
|
||||
#region Zip(根据传递的路径压缩成一个文件)
|
||||
/// <summary>
|
||||
/// 根据传递的路径压缩成一个文件
|
||||
/// </summary>
|
||||
/// <param name="filePaths"></param>
|
||||
/// <param name="savePath"></param>
|
||||
public static void Zip(List<string> filePaths, string savePath)
|
||||
{
|
||||
if (filePaths == null || filePaths.Count == 0) { }
|
||||
using (ZipFile zip = ZipFile.Create(savePath))
|
||||
{
|
||||
zip.BeginUpdate();
|
||||
|
||||
foreach (var path in filePaths)
|
||||
{
|
||||
var fileName = Path.GetFileName(path);
|
||||
zip.Add(path, fileName);
|
||||
}
|
||||
zip.CommitUpdate();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user