1
我想创建zip文件供用户下载并将该文件可以是任何文件,如图像或文本文件获取错误等当创建压缩文件下载
我想创建一个zip文件,下载它在我的锚点标签点击事件。
我有我的数据库表中的3个文件是这样的:
https://my.net/storage/log.txt
这是我的代码:
public ActionResult DownloadImagefilesAsZip()
{
string documentUrl = repossitory.GetDocumentsUrlbyId(id);//output:https://my.net/storage/log.txt,
https://my.net/storage/log1.txt,
https://my.net/storage/log2.txt,
if (!string.IsNullOrEmpty(documentUrl))
{
string[] str = documentUrl.Split(',');
if (str.Length > 1)
{
return new ZipResult(str);
}
}
}
public class ZipResult : ActionResult
{
public string[] Filename1 { get; private set; }
public ZipResult(string[] str)
{
Filename1 = str;
}
public override void ExecuteResult(ControllerContext context)
{
if (context == null)
{
throw new ArgumentNullException("context");
}
var response = context.HttpContext.Response;
response.ContentType = "application/gzip";
using (var zip = new ZipFile())
{
foreach (string t in Filename1)
{
if (!string.IsNullOrEmpty(t))
{
zip.AddFile(t);
}
}
//zip.AddDirectory(Path);
zip.Save(response.OutputStream);
var cd = new ContentDisposition
{
FileName = "Images.Zip",
Inline = false
};
response.Headers.Add("Content-Disposition", cd.ToString());
}
}
}
错误:给定的路径的格式不低于行支持:
zip.AddFile(t);
cting zip?那是什么意思? – DavidG
库是否支持将HTTPS URL传递给AddFile()?如果这是你正在使用的:http://dotnetzip.herobo.com/DNZHelp/html/b1d9ff87-214d-d219-af0c-8075512cb3a9.htm它说“它应该指文件系统中的文件” –
@DavidG :对不起没有让你 –