Не могли бы вы помочь в решении этой проблемы?
public string DownloadZip(string folderPath)
{
try
{
if (!Directory.Exists(folderPath))
return "ERROR: Folder not found";
string zipPath = Path.Combine(Path.GetTempPath(), "SPLDownload_" + Guid.NewGuid() + ".zip");
using (FileStream fsOut = System.IO.File.Create(zipPath))
using (ICSharpCode.SharpZipLib.Zip.ZipOutputStream zipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(fsOut))
{
zipStream.SetLevel(3);
var files = Directory.GetFiles(folderPath, "*.*", SearchOption.AllDirectories);
foreach (string file in files)
{
string entryName = file.Substring(folderPath.Length).TrimStart('\\');
var entry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(entryName)
{
DateTime = DateTime.Now,
Size = new FileInfo(file).Length
};
zipStream.PutNextEntry(entry);
byte[] buffer = new byte[4096];
using (FileStream fs = System.IO.File.OpenRead(file))
{
int bytesRead;
while ((bytesRead = fs.Read(buffer, 0, buffer.Length)) > 0)
{
zipStream.Write(buffer, 0, bytesRead);
}
}
zipStream.CloseEntry();
}
zipStream.Finish();
}
return zipPath; //
}
catch (Exception ex)
{
return "ERROR: " + ex.Message;
}
}