Imports System.Data.OleDb
Imports System.IO

Partial Public Class UdPdf
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim id As String = Request.Form("uudoc_fileid")

        If Request.Form("uudoc_getfile") = "1" Then '如果是提交请求文件

            '根据文件ID获取不同的加密文件或原始文件，需要根据实际情况编写自己的业务逻辑
            WriteFile(id)

            Response.End()
        End If

    End Sub

    '从数据库中读取文件
    Sub WriteFile(ByVal id As Integer)

        Dim connStr As String
        connStr = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & Server.MapPath("App_Data/database.mdb")

        Dim conn As OleDbConnection = New OleDbConnection(connStr)
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("select * from T_Files WHERE Id=" + id.ToString(), conn)
        Dim dt As DataTable = New DataTable()

        da.Fill(dt)

        If dt.Rows.Count > 0 Then
            Response.Buffer = False
            Response.ContentType = "application/octet-stream"
            Response.AddHeader("Content-Disposition", "attachment;filename=" & System.Web.HttpUtility.UrlEncode(dt.Rows(0)("FileName")))
            Response.AddHeader("Content-Length", dt.Rows(0)("FileContent").Length.ToString())
            Response.BinaryWrite(dt.Rows(0)("FileContent"))
        End If


    End Sub

End Class