Imports System.Data.OleDb Imports System.Io Public Class view Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents lblpcode As System.Web.UI.WebControls.Label Protected WithEvents Label3 As System.Web.UI.WebControls.Label Protected WithEvents lblpname As System.Web.UI.WebControls.Label Protected WithEvents lnkNext As System.Web.UI.WebControls.LinkButton Protected WithEvents image1 As System.Web.UI.WebControls.Image Protected WithEvents lnkprev As System.Web.UI.WebControls.LinkButton Protected WithEvents lnkback As System.Web.UI.WebControls.LinkButton Protected WithEvents Label5 As System.Web.UI.WebControls.Label Protected WithEvents lbldt As System.Web.UI.WebControls.Label Protected WithEvents lbldname As System.Web.UI.WebControls.Label 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Dim Rs As OleDbDataReader Dim con As New OleDbConnection, cmd As New OleDbCommand Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & MapPath("db") & "\db.mdb;" If con.State <> 0 Then con.Close() con.Open() lbldname.Text = Session("doctorcode") & "|" & Session("Doctorname") Session("pcode") = Request.QueryString("PCode") cmd.CommandText = "Select PatientCode,FileData,ContentType,FileName from PatientReport where DoctorCode='" & Session("DoctorCode") & "' and PatientCode='" & Session("pcode") & "'" cmd.Connection = con Rs = cmd.ExecuteReader Dim i = 1 While Rs.Read Dim objFileStream As FileStream Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(MapPath("images") & "\" & Session("DoctorCode") & "_" & Session("pcode")) Try dir.Create() Catch ex As Exception Response.Write(ex.ToString()) End Try Dim objBinaryWriter As BinaryWriter Dim strname As String, fileext() As String 'strname = Rs.GetValue(3) 'fileext = Split(strname, ".") 'strname = "myfile" & i & "." & fileext(1) strname = "myfile" & i & ".jpg" objFileStream = New FileStream(dir.FullName & "\" & strname, FileMode.Create) objBinaryWriter = New BinaryWriter(objFileStream) objBinaryWriter.Write(Rs.GetValue(1)) i = i + 1 objBinaryWriter.Close() Dim pcon As New OleDbConnection, pcmd As New OleDbCommand, prs As OleDbDataReader pcon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & MapPath("db") & "\db.mdb;" lblpcode.Text = Rs.GetValue(0) If pcon.State <> 0 Then pcon.Close() pcon.Open() pcmd.CommandText = "Select * from Patient where PatientCode='" & Rs.GetValue(0) & "'" pcmd.Connection = pcon prs = pcmd.ExecuteReader(CommandBehavior.KeyInfo) If prs.Read Then Dim dt() As String dt = Split(prs.GetValue(3), "/") lblpname.Text = prs.GetValue(1) lbldt.Text = dt(1) & "/" & dt(0) & "/" & dt(2) End If prs.Close() pcmd.Dispose() pcon.Close() End While Session("totcnt") = i - 1 Session("cnt") = 1 Session("back") = 1 display(Session("cnt")) End If End Sub Private Sub lnknext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkNext.Click Session("cnt") = Session("cnt") + 1 Session("back") = Session("cnt") If Session("cnt") > Session("totcnt") Then Session("cnt") = Session("totcnt") Session("back") = Session("totcnt") End If display(Session("cnt")) End Sub Public Sub display(ByVal i As Integer) Dim strname As String strname = "myfile" & i & ".jpg" Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(MapPath("images") & "\" & Session("DoctorCode") & "_" & Session("pcode")) If dir.Exists Then image1.ImageUrl = "images\" & Session("DoctorCode") & "_" & Session("pcode") & "\" & strname End If End Sub Private Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Unload cmd.Dispose() con.Close() End Sub Private Sub lnkprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkprev.Click Session("back") = Session("back") - 1 Session("cnt") = Session("back") If Session("back") = 0 Then Session("back") = 1 Session("cnt") = 1 display(Session("back")) Else display(Session("back")) End If End Sub Private Sub lnkBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lnkback.Click Dim i, j Dim dir As System.IO.DirectoryInfo = New System.IO.DirectoryInfo(MapPath("images")) Dim subdir() As System.IO.DirectoryInfo = dir.GetDirectories For i = 0 To subdir.Length - 1 If subdir(i).Exists Then Dim fl() As System.IO.FileInfo = subdir(i).GetFiles For j = 0 To fl.Length - 1 If fl(j).Exists Then fl(j).Delete() End If Next End If Next For i = 0 To subdir.Length - 1 If subdir(i).Exists Then subdir(i).Delete() End If Next If con.State <> 0 Then cmd.Dispose() con.Close() End If Server.Transfer("download.aspx?pcode=" & Session("pcode")) End Sub End Class