无法在FireFox中下载zip文件

时间:2019-11-12 21:22:25

标签: vb.net chilkat

我正在使用zip组件从内存中创建一个zip,并将该文件流式传输以进行下载。它工作了一段时间,但是在FireFox中,它不允许我下载文件。这是我正在使用的代码:


'  NewZip initializes the zip object.  It does not write
'  the file.  The "test.zip" file, in this case, will never be written.
success = zip.NewZip("lib-files.zip")
If (success <> True) Then
    'MsgBox(zip.LastErrorText)
    Exit Sub
End If
For Each oRow As Data.DataRow In oData.Tables(0).Rows
    If System.IO.File.Exists(Application("LibUploadedDocumentPath") & oRow("DocFileName").ToString) = True Then
        success = zip.AppendOneFileOrDir(Application("LibUploadedDocumentPath") & oRow("DocFileName").ToString, False)
        Dim entry As Chilkat.ZipEntry

        Dim fFile As FileInfo = New FileInfo(Application("LibUploadedDocumentPath") & oRow("DocFileName").ToString)
        Dim sNewFileName As String = oRow("DocName").ToString
        entry = zip.GetEntryByName(oRow("DocFileName").ToString)
        If (entry Is Nothing) Then
            MsgBox("Failed to find entry in .zip")
            Exit Sub
        End If
        'Dim sTestName As String = ""
        entry.FileName = sNewFileName & fFile.Extension.ToLower
    Else
        Response.Write("All the files are not found. Download aborted.")
        Exit Sub
    End If
Next
If (success <> True) Then
    'MsgBox(zip.LastErrorText)
    Exit Sub
End If
Dim Data As Byte()
Data = zip.WriteToMemory

Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length", Data.Length.ToString())
Response.AddHeader("Content-Disposition",
               "attachment; filename=""" & zip.FileName & """")
Response.BinaryWrite(Data)
Response.Flush()
Response.End()

在FireFox中,它说:“无法保存源文件,因为无法读取源文件”。我已经在Chrome浏览器中进行了尝试,并允许我在那里下载。不知道它是正在使用的组件,还是我需要添加的其他组件。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

也许将内容类型更改为“ application / zip”?

Response.ContentType =“应用程序/邮政编码”