simpledong

博客园 首页 新随笔 联系 订阅 管理
        Public Const CONTENT_ENC_JIS As String = "Shift_JIS"        'HEAD部分の文字コード
        Public Const CONTENT_TYPE As String = "application/vnd.ms-excel"    'HEAD部分のレスポンスデータ種別
        Public Const CONTENT_DISPOSITION_KEY As String = "Content-Disposition"  'HEAD部分のチャンネルの概要説明Key
        'HEAD部分のチャンネルの概要説明
        Public Const CONTENT_DISPOSITION_VALUE As String = "attachment; filename={0}"

        '--------------------------------------------------------
        'メソッド名:Download
        '概要    :出力ファイルをダウンロードする
        '引数    :FilePath = クライント端ファイルパス
        '引数    :strFileName = サーバー端ファイルパス
        '戻り値   :なし
        '--------------------------------------------------------
        Private Sub Download(ByVal FilePath As String, ByVal strFileName As String)
            'ファイル名
            Dim filename As String
            Try

                'Trace情報のログ出力()
                lm.SetTraceLog()

                'ファイル名を取得
                filename = strFileName  'System.IO.Path.GetFileName(FilePath)
                'ダウンロードファイル名をエンコード
                filename = System.Web.HttpUtility.UrlEncode(filename)

                'レスポンス情報を削除
                Page.Response.ClearHeaders()
                Page.Response.ClearContent()
                '文字コードをShift_JISに設定
                Page.Response.Charset = CONTENT_ENC_JIS
                'エンコードタイプをShift_JISに設定
                Page.Response.ContentEncoding = System.Text.Encoding.GetEncoding(CONTENT_ENC_JIS)
                'レスポンスデータ種別をEXCELに設定
                Page.Response.ContentType = CONTENT_TYPE
                'レスポンスにファイル名を設定
                Page.Response.AppendHeader(CONTENT_DISPOSITION_KEY, _
                                            String.Format(CONTENT_DISPOSITION_VALUE, filename))

                Response.Buffer = True
                ' Flush the data to the HTML output.
                Response.Flush()

                ' Download the file.
                Response.WriteFile(FilePath)

                'レスポンスデータをクライアントに送信し、レスポンスを閉じる
                'Page.Response.Clear()
                Page.Response.End()

            Catch afEx As AfException
                Dim sf As New StackFrame(True)
                afEx.AddStackFrame(sf)
                '上位に例外をスローする
                Throw afEx
            Catch ex As Exception
                'Dim afEx As New AfException(ex, AfMessages.GetMessageText(CM02001))
                ''上位に例外をスローする
                'Throw afEx
                'スレッド中止による例外以外であれば、エラー処理を実行
                If Not ex.GetType Is GetType(System.Threading.ThreadAbortException) Then
                    'エクスポート中に例外が発生した場合の処理
                    Dim afEx As New AfException(ex, "EXCELファイルの作成に失敗しました")
                    '上位に例外をスローする
                    Throw afEx
                Else
                    'スレッド中止による例外であれば、継続発生を回避する
                    Threading.Thread.ResetAbort()
                End If
            End Try
        End Sub
posted on 2006-02-10 17:09  simple  阅读(676)  评论(0编辑  收藏  举报