Код: Выделить всё
var zipfilep = CreateZipFile(fileByteArrays, sfileNames);
if (File.Exists(zipfilep))
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/zip";
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(zipfilep));
byte[] fileBytes = File.ReadAllBytes(zipfilep);
HttpContext.Current.Response.BinaryWrite(fileBytes);
HttpContext.Current.Response.Flush();
File.Delete(zipfilep);
}
< /code>
public string CreateZipFile(List files, List sfileNames)
{
string tempFolder = Server.MapPath("~/Upload");
string zipFilePath = Path.Combine(tempFolder, GetGlobalResourceObject("GestioneContabilita", "RDLCViewer_ZipReportName").ToString() + ".zip");
using (Package zip = Package.Open(zipFilePath, FileMode.Create))
{
for (int i = 0; i < files.Count; i++)
{
string zipPartUri = $"/{Uri.UnescapeDataString(sfileNames[i])}";
Uri partUri = PackUriHelper.CreatePartUri(new Uri(zipPartUri, UriKind.Relative));
PackagePart part = zip.CreatePart(partUri, System.Net.Mime.MediaTypeNames.Application.Octet, CompressionOption.Normal);
using (Stream partStream = part.GetStream())
{
partStream.Write(files[i], 0, files[i].Length);
}
}
}
return zipFilePath;
}
Windows не может открыть папку. C: \ users \ userprofile \ downloads \ reports.zip недействителен
, а также я проверил отчеты на Server.mappath ("~/upload") имеет размер 15,175 кб, но после httpcontext.current.response.binarywrite (filebytes); в C: \ users \ userprofile \ Downloads \ reports.zip превращается в 15 569 KB < /p>
В чем может быть проблема?
Я должен использовать .NET Framework 4.0 < /p>
Подробнее здесь: https://stackoverflow.com/questions/794 ... in-c-sharp
Мобильная версия