我正在为 Sharepoint 编写一个应用程序,该应用程序在功能区上实现一个按钮,以将多个文件下载为 zip...
一切顺利,一切顺利……但是当我尝试使用 Chrome 或 Firefox 下载 zip 时,他们什么也没做……
我的代码是这样的:
private void WriteStreamToResponse(MemoryStream ms)
{
if (ms.Length > 0)
{
string filename = DateTime.Now.ToFileTime().ToString() + ".zip";
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/zip"; //also tried application/octect and application/x-zip-compressed
Response.AddHeader("Content-Length", ms.Length.ToString());
Response.AddHeader("Content-Disposition", "attachment; filename=" + filename);
byte[] buffer = new byte[65536];
ms.Position = 0;
int num;
do
{
num = ms.Read(buffer, 0, buffer.Length);
Response.OutputStream.Write(buffer, 0, num);
}
while (num > 0);
Response.Flush();
}
}