ASP.NET Create zip file for download: the compressed zipped folder is invalid or corrupted

前端 未结 1 1868
广开言路
广开言路 2021-02-03 15:18
string fileName = \"test.zip\";
string path = \"c:\\\\temp\\\\\";
string fullPath = path + fileName;
FileInfo file = new FileInfo(fullPath);

Response.Clear();
Response.         


        
1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-03 15:32

    This worked. I don't know why but it did.

    string fileName = "test.zip";
    string path = "c:\\temp\\";
    string fullPath = path + fileName;
    FileInfo file = new FileInfo(fullPath);
    
    Response.Clear();
    //Response.ClearContent();
    //Response.ClearHeaders();
    //Response.Buffer = true;
    Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName);
    //Response.AppendHeader("Content-Cength", file.Length.ToString());
    Response.ContentType = "application/x-zip-compressed";
    Response.WriteFile(fullPath);
    //Response.Flush();
    Response.End();
    

    0 讨论(0)
提交回复
热议问题