私が達成しようとしているのは、ユーザーがSilverlightアプリケーションから複数のファイルをダウンロードできるようにすることです。これを行うために、データベースからすべてのファイルを取得してクライアントに送信するDotNetZip
ライブラリとASP.NET
ハンドラーを使用することにしました。それは良い考えであり、実装が簡単なようでした。単純なハンドラーを作成し、必要なすべてのコードを記述して、すべてが機能しました。
しかし、どういうわけか、たくさんのファイルでzipファイルを作成すると問題が発生します。The remote host closed the connection. The error code is 0x800704CD.
にデータを書き込もうとすると、例外がスローされResponse
ます。
Private Sub MultipleFileDownload_Loaded(sender As Object, e As EventArgs) Handles Me.Load
// initialize data and stuff
_context.Response.Clear()
_context.Response.BufferOutput = False
Me.ZipElementsIntoOutputStream(elementsToDownload)
_context.Response.End()
End Sub
Private Sub ZipElementsIntoOutputStream(elements As List(Of ElementImageFile))
_context.Response.ContentType = "application/zip"
Dim archiveName As String = String.Format("archive-{0}.zip", DateTime.Now.ToString("yyyy-MM-dd-HHmmss"))
_context.Response.AddHeader("content-disposition", "attachment; filename=" + archiveName)
Using zip As New ZipFile()
For Each elementToDownload In elements.Where(Function(e) e IsNot Nothing AndAlso e.File IsNot Nothing)
Dim fileName = Me.GetUniqueFileName(elementToDownload, zip)
zip.AddEntry(fileName, elementToDownload.File)
Next
Using s As IO.MemoryStream = New IO.MemoryStream()
zip.Save(s)
s.Seek(0, IO.SeekOrigin.Begin)
Dim buffer(10000) As Byte
Dim length As Integer
Dim dataToRead As Long
dataToRead = s.Length
While dataToRead > 0
If (Me._context.Response.IsClientConnected) Then
length = s.Read(buffer, 0, 10000)
Me._context.Response.OutputStream.Write(buffer, 0, length)
Me._context.Response.Flush()
ReDim buffer(10000)
dataToRead = dataToRead - length
Else
dataToRead = -1
End If
End While
'zip.Save(_context.Response.OutputStream)
End Using
End Using
End Sub
ご覧のとおり、同様の問題の解決策として示されているように、MemoryStream
小さなデータを作成してに送信していますが、これは役に立ちませんでした。ファイルをに直接Response
保存すると、まったく同じエラーが発生します。Zip
Response
BufferOutput
プロパティはFalse
、すぐにダウンロードを開始するように設定されていますが、に変更してTrue
も何も変更されません。
zip
私が送信しようとしているファイルは約248メガバイトであり、これによりエラーが発生します。いくつかの要素を削除し、zip
ファイルが約220メガバイトになると、すべてが正常に機能しているように見えます。
誰かが知っていますか、この動作の理由は何でしょうか?どうすればこれを修正できますか?zipファイルを送信してもこのエラーは発生しませんか?