我有一个asp.net网页,位于我网站的安全区域内。
有一个文件列表,您可以在其中选择一些文件,然后单击一个按钮,然后将这些文件放入一个用户将被要求下载的zip文件中。
使用ipad和chrome时,它无法正常工作。它重定向到一个空白页面,并显示我的aspx页面的名称。 Ipad和safari很好。桌面和Chrome很好。
如果我直接转到zip文件,它会在ipad和chrome上正确下载,但如果网页动态创建zip文件则不会。
以下是我正在使用的代码。有谁知道为什么?已经难倒了一个星期。我正在使用名为ionic.zip.dll的dll
protected void btnDownload_OnClick(object sender, EventArgs e)
{
ArrayList arrayZipFiles = new ArrayList();
//Loop throug all rows in the Files grid looking for which records are checked
foreach (GridDataItem gdiFiles in gridFiles.MasterTableView.Items)
{
CheckBox chkSelected = (CheckBox)gdiFiles.FindControl("chkDownload");
if (chkSelected.Checked)
{
//Add to the ArrayList
String strFullFilename = gdiFiles.Cells[6].Text.ToString();
arrayZipFiles.Add(strFullFilename);
}
}
//Pass ArrayList to function which pushes in to Zip and initiates the download
if (arrayZipFiles.Count > 0)
DownloadFiles(arrayZipFiles);
}
protected void DownloadFiles(ArrayList arrayZipFiles)
{
if (arrayZipFiles.Count > 0)
{
String strOrderNo = String.Empty;
foreach (GridDataItem gdiItem in gridOrders.SelectedItems)
{
//Get order No to use as filename for zip file
strOrderNo = gdiItem["OrderNo"].Text.ToString();
}
Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + strOrderNo + ".zip");
using (ZipFile zip = new ZipFile())
{
foreach (string strItemToZip in arrayZipFiles)
{
zip.AddFile(strItemToZip, "");
}
zip.Save(Response.OutputStream);
Response.End();
}
}
}