0

バイナリ列に格納されているSQLServerデータベースからPDFファイルをダウンロードしたい。aspxページにLinkBut​​tonがあります。このボタンのイベントハンドラは次のようになります。

protected void LinkButtonDownload(object sender, EventArgs e)
{
    ...
    byte[] aByteArray;
    // Read binary data from database into this ByteArray
    // aByteArray has the size: 55406 byte

    Response.ClearHeaders();
    Response.ClearContent();
    Response.BufferOutput = true;

    Response.AddHeader("Content-Disposition", "attachment; filename=" + "12345.pdf");
    Response.ContentType = "application/pdf";

    using (BinaryWriter aWriter = new BinaryWriter(Response.OutputStream))
    {
        aWriter.Write(aByteArray, 0, aByteArray.Length);
    }
}

「ファイルを開く/保存するダイアログ」がブラウザに表示されます。このファイル「12345.pdf」をディスクに保存すると、ファイルのサイズは71523バイトになります。PDFファイルの最後に追加された16kBは、私のページのHTMLコードです(エディターでファイルを表示するとわかります)。ClearContentとClearHeadersを使用すると、ページのコンテンツがファイルのコンテンツと一緒に送信されないようになると信じていたため、混乱しています。

私はここで何が間違っているのですか?

手伝ってくれてありがとう!

4

2 に答える 2

3

このメソッドの最後に Response.End が必要だと思います。

于 2010-03-17T20:11:03.957 に答える
3

一見すると、Response.End(); がありません。

于 2010-03-17T20:12:19.850 に答える