Option Explicit On
Option Strict On

''' <summary>
''' Excelファイルダウンロード用ページ
''' </summary>
''' <remarks></remarks>
''' 
Public Class XlsDownloadPage
    Inherits System.Web.UI.Page

    ''' <summary>
    ''' ロードイベント
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim wXlsName As String = String.Empty
        Dim wRepName As String = String.Empty

        '----- ダウンロードファイルの情報を取得 
        Try
            wXlsName = DirectCast(Session.Contents("Xls_DownLoad_FilePath"), String)
        Catch ex As Exception
            wXlsName = String.Empty
        End Try
        Try
            wRepName = DirectCast(Session.Contents("Xls_DownLoad_FileName"), String)
        Catch ex As Exception
            wRepName = String.Empty
        End Try

        '----- ダウンロード 
        If wXlsName <> "" AndAlso wRepName <> "" Then
            Response.HeaderEncoding = System.Text.Encoding.GetEncoding("shift_jis")
            Response.ContentEncoding = System.Text.Encoding.GetEncoding("shift_jis")
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(wRepName) & ".xls")
            Response.WriteFile(wXlsName)
            Response.Flush()
        End If

        'セッション破棄
        Session.Remove("Xls_DownLoad_FilePath")
        Session.Remove("Xls_DownLoad_FileName")

    End Sub

End Class